utpalmtbi has asked for the wisdom of the Perl Monks concerning the following question:
Monks!!!
I try to trim file content headers in the format '>bla|bla|bla' in one or two fields. For that I have used:
while (<>) { if (/^>/) { my @fields = split '\|', $_; if (@fields <= 2) { print "$fields[0]\n"} else { print join '|', "@fields[0,1]\n" } next; } print; }
When it prints two fields (second print) it prints like this >bla bla (that is, a space in between), but I need to print them with a pipe in between and with no space (that is >bla|bla).
Without writting another regex to replace space with pipe, how to do that in current script?
Thanks
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Join without space in this perl script
by hippo (Archbishop) on Nov 19, 2016 at 10:14 UTC | |
by utpalmtbi (Acolyte) on Nov 19, 2016 at 10:24 UTC |