Re: Shortening a script, but aiming for efficiency

[email protected] (Alan Young)
Newsgroups perl.fwp
Message-ID <[email protected]>
> a\tb\t
> a\t\t
> \tb\t
> \t\t\t
> 
> The output for all these should be:
> 
> a|b
> a|\s
>  |b
>  |\s
> 
> This means that I could start by replacing all tabs with pipes, but then
>  I would always have to remove the last pipe...
> 
> I could replace two ending pipes with "| " (second and fourth cases),
>  but I would also have to remove a single ending pipe (first and third
>  cases)

Then use a '+':

s/\|+$/ /;
-- 
Alan
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.