Under the assumption that @head stays constant during the loop, do you declare the hash outside of the loop? As the keys of the hash are same every iteration, it would be wasteful, to create and delete the hash structure, allocate memory for the keys, etc every time. So it should be similar to this (leaving chomping aside for the moment):
my @head = split /\t/, <$fh>; my $ref = {}; undef @{$ref}{@head}; # pre-allocate the hash and its keys for( <$fh> ) { @{$ref}{@head} = split /\t/; # do something with the data here }
In reply to Re: Faster Hash Slices
by hdb
in thread Faster Hash Slices
by jht
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |