Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

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

by trs80 (Priest)
on Jun 06, 2003 at 18:35 UTC ( [id://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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (4)
As of 2024-04-20 00:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found