[ABE.pm] perl regex Q

Jim Eshleman jce0 at Lehigh.EDU
Tue Dec 14 21:56:23 CST 2004


>>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.
> 
>  
> I think you mean: 
> perl -ne 'chomp;print join(",",map {defined $_ ? $_ : "\\N"} split ",",$_,-1), "\n"'
> 
> Otherwise, a 0 will become a \N    :)

Actually, that doesn't work at all (just reproduces the input string) 
because when there's no value between delimiters split returns the empty 
string ('') and that *is* defined.

   What we really meant is:

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

   Now we can process zeros (0) and zeros (0.0)  :)
-------------- 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/d8e1bcaa/signature-0001.bin


More information about the ABE-pm mailing list