Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Read File In Four-Line Chunks / TMTOWTDI / Golf

by trs80 (Priest)
on Jun 06, 2003 at 18:35 UTC ( #263812=note: print w/ replies, xml ) Need Help??


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

UPDATE - first post didn't keep them in named variables

use strict; use Data::Dumper; my @four; my @all; my $count = 0; while (<DATA>) { s/\s+$//; push @four , $_; $count++; if ( ($count % 4) == 0) { my %hash; @hash{'name','address','phone','fax'} = @four; push @all , \%hash; @four = (); } } print Dumper(\@all); __DATA__ name1 address1 phone1 fax1 name2 address2 phone2 fax2
original post below
use strict; use Data::Dumper; my @four; my @all; my $count = 0; while (<DATA>) { s/\s+$//; push @four , $_; $count++; if ( ($count % 4) == 0) { push @all , [ @four ]; @four = (); } } print Dumper(\@all); __DATA__ name1 address1 phone1 fax1 name2 address2 phone2 fax2


Comment on Re: Read File In Four-Line Chunks / TMTOWTDI / Golf
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2014-09-20 04:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (152 votes), past polls