Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^3: Insert row from file

by Gilimanjaro (Hermit)
on Feb 04, 2005 at 11:16 UTC ( #428010=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Insert row from file
in thread Insert row from file

It works because of the way the while loop works: The conditional in the while loop always gets evaluated first, before the content of the loop block. The <A> operator, when used in a while conditional, assigns the line gotten from file A to $_, starting with the 1st line.

The body of the loop, again uses the <A> operator, which gets the next line; you can access a line only once using the <> operator. I use it directly as the key to the %pairs hash, so the key is the 2nd line. It assigns the value of $_ (which was set in the while conditional) to this element of %pairs.

The loop evaluates the conditional again, gets the 3rd line, and assigns it to $_, and the body does the same all over again with the fourth line. So the even/odd mechanism is caused by the double use of <A>.

If I wanted to key on the odd lines, I'd've used $pairs{$_}=<A>;


Comment on Re^3: Insert row from file
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (12)
As of 2014-07-30 15:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (235 votes), past polls