[ABE.pm] perl regex Q
faber at sedna.linuxnj.com
faber at sedna.linuxnj.com
Tue Dec 14 22:32:51 CST 2004
On Tue, Dec 14, 2004 at 10:56:23PM -0500, Jim Eshleman wrote:
> >>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) :)
Either of you boys wanna explain this to us mere mortals?
More information about the ABE-pm
mailing list