On Sun, 18 Jan 2015 19:00:05 -0500 Mike <ekimduna...@gmail.com> wrote:
> sub gen_ins { > open(FH, '<', 'insults2.txt') or die "[-] ERROR: Can't find > insult list."; > my @cols = split (" ", <FH>); > print "$cols[0]"; > close FH; > } > > gen_ins(); > > When currently run, gen_ins() will print out the first word of the > given column: $cols[0], $cols[1], or $cols[2]. How can I access the > rest of the words below the first? 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]; } 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"; } -- Don't stop where the ink does. Shawn -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/