in reply to pipe delimited file problem
For what it's worth, I second imp's suggestion to use split. Even though the split version
is a little longer than the regex$_ = join '|', map {$_ ||= 'empty' } split('\|',$_,-1);
It's closer to how one thinks of a delimited record, and so it's easier to change if you need to.s/(?<=\|)\|/empty|/g;
One difference is that the split version puts the 'empty' string in the first field, if it's empty, while the regex version doesn't, So that may be the most significant difference for you.
Update: Corrected missing negative limit in split. See graff's comment.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: pipe delimited file problem
by graff (Chancellor) on Jan 22, 2007 at 03:34 UTC |
In Section
Seekers of Perl Wisdom