Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^3: Faster Hash Slices

by Laurent_R (Canon)
on Nov 29, 2013 at 23:22 UTC ( [id://1065006]=note: print w/replies, xml ) Need Help??


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:

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>
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.

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
    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.

    What "discussed command"? The OP doesn't mention any command; nor show any "command".

    You appear to be assuming that the op reads all the lines of the file; and then runs this "discussed command" once the rad loop ends; but there is no evidence of that within the thread.

    An alternative scenario: He reads a line; splits it to the hash; accesses a few named fields and performs some calculation that affects some variables declared before the loop is entered; and then loops back and reads the next line; until the file is read.

    There is no evidence from the OP one way or the other anywhere in the thread, but to assume your version is to assume the OP is ...


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

      Well, quite possible, I may have misinterpreted the OP. However the OP specifically said:

      I have a program that reads and processes approximately 8 million line +s of data. For each line read it does: my @aa = split(/\t/); @{$ref}{@head} = @aa;
      It seems to indicate that the program is executing the two lines of code above for each of the 8 million lines of input. Quite possibly the program may be doing something else, but this was just exactly what I was asking for, more code if any.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1065006]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (7)
As of 2024-04-23 11:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found