in reply to Getting feet wet with hashes
Better would be to do something like:
However, even better would be to use a hashslice, similar to an arrayslice. That syntax would look something like:while (my $line = <INFILE>) { my @line = split /\t/, $line; my %hash = ( key0 => $line[0], key1 => $line[1], key2 => $line[2], key3 => $line[3], key4 => $line[4], ); print "Key 3 is $hash{key3}\n"; push @lines_of_file, \%hash; }
The two snippets produce identical results, except the second is, in my mind, easier to handle. Some prefer the first, and that's perfectly fine.while (my $line = <INFILE>) { my %hash; @hash{qw(key0 key1 key2 key3 key4)} = split /\t/, $line; print "Key 3 is $hash{key3}\n"; push @lines_of_file, \%hash; }
------
We are the carpenters and bricklayers of the Information Age.
Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.
|
|---|