Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
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 studying the Monastery: (9)
As of 2015-07-05 18:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (67 votes), past polls