Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^2: Optimal way to read in pipe delimited files

by bageler (Hermit)
on Nov 09, 2005 at 19:49 UTC ( [id://507194]=note: print w/replies, xml ) Need Help??


in reply to Re: Optimal way to read in pipe delimited files
in thread Optimal way to read in pipe delimited files

you can take this two steps further by getting rid of $key and using a map:
%prod=map{chomp;@a=split/\|/;shift@a,[@a]}<SRC>;
or, expanded,
%prod = map { chomp; @a = split /\|/; shift(@a) => [@a] } <SRC>
You have to do [@a] instead of \@a if you do not localize the array with "my".

Replies are listed 'Best First'.
Re^3: Optimal way to read in pipe delimited files
by Roy Johnson (Monsignor) on Nov 09, 2005 at 22:29 UTC
    I think that's one step too far. Specifically, getting rid of a descriptive scalar in favor of lumping all the values together and using shift. I don't see any advantage in performance or clarity.

    Caution: Contents may have been coded under pressure.
Re^3: Optimal way to read in pipe delimited files
by narashima (Beadle) on Nov 09, 2005 at 22:34 UTC

    Could someone please explain the significance of shift@a,[@a] in the above map? I tried removing this statement and it did not work. I really dont know what that statement is doing.
    Also I did not understand why [@a] is to be used if my is not used.
    thanks
    narashima

      Because my gives you a new variable each time through the loop, you can use \@a and all it well because it's a different @a each time. When you don't use my within the loop, it's always the same variable. Thus @a = (1,2,3); $a = \@a; @a =(4,3,9); $b = \@a; will cause $a and $b to both reference the same memory location which will contain the values (4,3,9). [@a] makes a copy of @a and returns a reference to it, so you get a new chunk of memory each time.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2024-04-23 16:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found