[ABE.pm] perl regex Q

Jim Eshleman jce0 at Lehigh.EDU
Tue Dec 14 19:08:44 CST 2004


> I have a text file that contains lines like
> 
>     1.2,3.4,,5.67,78.9,,,,,0.01
> 
> I want to make the line look like this:
> 
>     1.2,3.4,\N,5.67,78.9,\N,\N,\N,\N,0.01

This:

perl -ne 'chomp;print join(",",map {$_ or "\\N"} split ",",$_,-1), "\n"'

should work and handle the corner cases of leading and/or trailing 
commas.  Likely not as fast as a regex but *maybe* easier to understand.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 252 bytes
Desc: OpenPGP digital signature
Url : http://mail.pm.org/archives/abe-pm/attachments/20041214/22c76404/signature.bin


More information about the ABE-pm mailing list