Beefy Boxes and Bandwidth Generously Provided by pair Networks Bob
P is for Practical
 
PerlMonks  

Re: Parsing multi-line records

by frankus (Priest)
on Dec 04, 2001 at 20:42 UTC ( #129362=note: print w/ replies, xml ) Need Help??


in reply to Parsing multi-line records

use $/=undef to slurp all the file into a string. Replace all \n with commas except for the 12th?

$/=undef; # Slurps all data in file. $_=<DATA>; # Put it in $_, convenient for regex. my $lines=0; # Line count $. might suffice and then the pre increme +nt can be dropped. my $records=11; # Number of lines in a record. s/\n/(',',"\n")[++$line%$records==0]/eg;# replaces all \n with commas +except the recordth. print $_;

--

Brother Frankus.

¤


Comment on Re: Parsing multi-line records
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (9)
As of 2014-04-21 15:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (495 votes), past polls