in reply to Re: Broken regexp
in thread Broken regexp
$line=join('|',map(defined($_) ? $_ : '\N', split('|',$line)));'
Empty fields will be defined, but empty. In other words: they will be strings with a length of 0 (also: "without length"). Besides that, $_ is the default variable. I prefer to see people take advantage of that :)
Your code will also not work because it splits on either nothing or nothing. Using '' instead of // doesn't make split interpret its first argument as a string. It always sees it as a regex, unless it is ' ' (a single chr(32) space). The | needs to be escaped.
Oh, and I dislike parens. Without parens, I think things are much easier to read.
$line = join '|', map { length() ? $_ : '\N' } split /\|/, $line, -1.
Update 1 - added negative third argument for split per Abigail's suggestion.
Update 2 - added some parens per Abigail's second suggestion.
Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Broken regexp
by Abigail-II (Bishop) on Mar 09, 2004 at 13:44 UTC | |
by Juerd (Abbot) on Mar 09, 2004 at 14:06 UTC | |
|
Re: Re: Re: Broken regexp
by liz (Monsignor) on Mar 09, 2004 at 14:31 UTC | |
by Juerd (Abbot) on Mar 09, 2004 at 14:47 UTC | |
by ysth (Canon) on Mar 09, 2004 at 16:20 UTC |