Problem -- I have a file. I want to read it in four-line chunks, because it goes
and so on.name1 address1 phone1 fax1 name2 address2 phone2 fax2
Solution? My first one was to slurp and then do like this:
which makes me wince to look at it.for($i=0;$<scalar(@slurpedarray);$i+=4){ # work with $slurpedarray[$i], $slurpedarray[($i+1)], # $slurpedarray[($i+2)] and $slurpedarray[($i+2)] }
Now I'm going to do it with the much more Perlish
while(@slurpedarray){ ($name,$address,$phone,$fax) = splice(@slurpedarray,0,3) # work with nice named vars }
Interesting bit: all these solutions are based on whole-file slurpage (fine for me, very small files) but the interesting solutions were the ones which didn't do that, the ones for actually reading the file itself.
Any interesting solutions? (Stands back...)
--
Every bit of code is either naturally related to the problem at hand, or else it's an accidental side effect of the fact that you happened to solve the problem using a digital computer.
M-J D
In reply to Read File In Four-Line Chunks / TMTOWTDI / Golf by Cody Pendant
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |