in reply to Re^2: Faster Hash Slices
in thread Faster Hash Slices
I might not have expressed myself correctly, but I was only trying to say that, since $ref and @head are never changing in the presented code, each time through the loop, the values of @aa will clobber the previously recorded ones, so that the loop is in effect useless, it would be faster to go straight to the last line of the file, split it and run the discussed command only once. Example under the Perl debugger:
The assignment of line 4 is clobbering what was previously in the hash referenced by $ref. It does not make sense to do that in a loop, since only the last assignment of the loop is useful.DB<1> @head = qw 'foo bar baz' DB<2> @{$ref}{@head} = qw /one two three/; DB<3> x $ref 0 HASH(0x8032f9b8) 'bar' => 'two' 'baz' => 'three' 'foo' => 'one' DB<4> @{$ref}{@head} = qw /four five six/; DB<5> x $ref 0 HASH(0x8032f9b8) 'bar' => 'five' 'baz' => 'six' 'foo' => 'four' DB<6>
Or the real code is different, in which case it might be useful to see the real code.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Faster Hash Slices
by BrowserUk (Patriarch) on Nov 30, 2013 at 00:39 UTC | |
by Laurent_R (Canon) on Nov 30, 2013 at 19:05 UTC |