Andy Lester wrote: > > I wrote up a little band name generator that sucks up /usr/dict/words and > cranks out band names. They turn out to be eerily feasible. > > xoxo, > Andy > > #!perl -w > > use strict; > > open( IN, "<words.txt" ) or die; > my @dict = <IN>; > close IN; > chomp @dict; > > #warn "Read ", scalar @dict, " words\n"; > while ( my $mask = <DATA> ) { > my @words; > for ( 1..5 ) { > push( @words, ucfirst @dict[ int(rand scalar @dict) + 1 ] ); > } > printf( $mask, @words ); > } # while > > __END__ > The %s %s > The %s %s of %s > %s %s and the %s > %s and the %s %s > %s %s > %s > > -- > Andy Lester > andy@petdance.com Cool... I got some good names... But the line push( @words, ucfirst @dict[ int(rand scalar @dict) + 1 ] ); has a few problems: 1) "+ 1" should not be there (arrays are zero based) 2) the first "@dict" should be $dict (one value at a time) 3) the "int" is not needed (forced by []) 4) the "scalar" is not needed (context from rand) I must need help, 'cause I shortened it to: #!/usr/bin/perl -w use strict; chomp(my @dict = `cat /usr/dict/words`); printf $_, map ucfirst $dict[rand @dict], 1..3 while <DATA>; __END__ The %s %s The %s %s of %s %s %s and the %s %s and the %s %s %s %s %s (Perl is sure fun...) -- Rick ==== Want to unsubscribe from Fun With Perl? Well, if you insist... ==== Send email to <fwp-request@technofile.org> with message _body_ ==== unsubscribe