Adding a PIPE delimiter at end of line

I already have parsed a file and delimited it with PIPE (|) --- except after the last field.
Is there a way I can add the PIPE  (|) delimeter at the end of the line without doing the whole thing again? I need some sort of global pattern search and add or update feature.
tgbekeleAsked:
Who is Participating?
 
maneshrConnect With a Mentor Commented:
replace


$var=~ s/\n/\|\n/;

with
$var=~ s/$/\|/;


and that will be solved too...
0
 
maneshrCommented:
you can use the \n char as your reference, since \n indicates end of line. Basically search for \n and replace it with a | and \n

Eg.
lets say each line of your file is stored in a var called $var.
$var is in a loop.

open(FILE,"the_piped_file") || die $!;
while $var(<FILE>){
$var=~ s/\n/\|\n/;
}
close(FILE);

0
 
tgbekeleAuthor Commented:
maneshr,

thank you ... works great as long as the last column in the data is not blank ... for those lines that have a blank space, it is not placing the |.
Any ideas why?
0
 
ozoCommented:
{local $^I=''; local @ARGV=('the_piped_file');
  while( <> ){ s/$/|/; print }
}
0
 
tgbekeleAuthor Commented:
Thank you very much ... that worked!!!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.