in reply to Read File In Four-Line Chunks / TMTOWTDI / Golf

Not a big change but you can do
while (my ($name,$address,$phone,$fax) = splice(@slurpedarray,0,4)){ #work with named vars }
The last splice argument there should be 4 since its a length not an index.

Replies are listed 'Best First'.
Re: Re: Read File In Four-Line Chunks / TMTOWTDI / Golf
by halley (Prior) on Jun 10, 2003 at 13:53 UTC

    Instead of slurping everything at once, just read the handle four times. Then you can deal with multi-gigabyte phonebooks.

    while (my ($name,$address,$phone,$fax) = (<FILE>, <FILE>, <FILE>, <FIL +E>)) { #work with named vars (don't forget chomp) }

    Update: just did a little test, and it does one iteration and stops. Hm.

    --
    [ e d @ h a l l e y . c c ]

      You're using <FH> in a list context so it would read in the entire file in the first iteration
      Update: apologies I'm speaking rubbish there. I did a quick test my self and it picks up the data you would expect but only does iterate the once.