On Sun, Jan 18, 2015 at 07:24:21PM -0500, Shawn H Corey wrote: > You would need an array for each column: > > my $MAX = 10; > > my @first = (); > my @second = (); > my @third = (); > > sub get_columns { > my $file = shift @_; > > open my $fh, '<', $file or die "could not open $file: $!\n"; > while( <$fh> ){ > my @items = split; > push @first, $items[0]; > push @second, $items[0]; > push @third, $items[0];
Minor typo there. I believe that Shawn meant: push @first, $items[0]; push @second, $items[1]; push @third, $items[2]; Alternatively, eliminate the @items array entirely and assign to a list of 3 lexical variables. For example: my ($first, $second, $third) = split; push @first, $first; push @second, $second; push @third, $third; > } > close $fh or die "could not close $file: $!\n"; > } > > get_columns( 'insults2.txt' ); > > for ( 1 .. $MAX ){ > my @line = ( > @first[rand(@first)], > @second[rand(@second)], > @third[rand(@third)], > ); > print "@line\n"; > } Regards, -- Brandon McCaig <bamcc...@gmail.com> <bamcc...@castopulence.org> Castopulence Software <https://www.castopulence.org/> Blog <http://www.bambams.ca/> perl -E '$_=q{V zrna gur orfg jvgu jung V fnl. }. q{Vg qbrfa'\''g nyjnlf fbhaq gung jnl.}; tr/A-Ma-mN-Zn-z/N-Zn-zA-Ma-m/;say'
signature.asc
Description: Digital signature