What I am about to do is stupid (and the long way around), but I just feel like playing around today... so here's a different and more generic way to think about it ... fixing bad input... this should work in scenarios other than just split, call it "thinking outside the box", if you will. Of course, I prefer "there is no box". But there might be a spoon. Or at least a spork. Anyway....
$text = 'a|b|c|||||||||e||||';
@array = split(/\|/,$text);
print join '-', @array;
can become ...
$text = 'a|b|c|||||||||e||||'; # our input might have holes in it!
$text =~ s#\|\|#\|NULL\|#g; # make holes read as 'NULL'
@array = map { $_ eq 'NULL' ? undef : $_ } split(/\|/,$text);
print join '-', @array;
Code is of course untested, but you see the general madness of it. We're filling up a hole with something, digging up the hole, and then getting the hole back just like we left it :) Ok I just like overusing map. If you have a map, everything looks like a nail. Good thing Magellan didn't have a map.
|