Thanks. I'll give this a shot.
On 1/18/15 7:44 PM, Brandon McCaig wrote:
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,
-- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected] http://learn.perl.org/
