readline the file into a map, chomp the line terminator, split on pipes, grep for length to remove empty fields and pass to a second map as an anonymous array which you join with pipes again.
$ perl -Mstrict -Mwarnings -E ' open my $inFH, q{<}, \ <<EOF or die $!; IFB Northpole||| Alaska||| 907-555-5555 Walmart||| Fairbanks||| Alaska Chicken||| Anchorage||| Alaska||| 907-555-5555 Beef||| Somewhere|||||Over the Rainbow|||907-555-5555 EOF say for map { join q{|}, @$_ } map { chomp; [ grep { length } split m{\|} ] } <$inFH>;' IFB Northpole| Alaska| 907-555-5555 Walmart| Fairbanks| Alaska Chicken| Anchorage| Alaska| 907-555-5555 Beef| Somewhere|Over the Rainbow|907-555-5555 $
I hope this is helpful.
Cheers,
JohnGG
In reply to Re: how to remove empty pipe delimiters in a line which doesn't contain any data
by johngg
in thread how to remove empty pipe delimiters in a line which doesn't contain any data
by rpinnam
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |