in reply to regexp, substitution and the "pipe symbol"

jockel,
Sometimes it is easier to break the problem up into smaller pieces, and that's why it is so nice that there is always more than one way to do it.
#!/usr/bin/perl -w use strict; my $string = 'column1 |column two |might be column3'; my @columns = split /\|/ , $string , -1; $_ =~ s/\s+$// for @columns; $string = join '|' , @columns;
Cheers - L~R
Updated: Added -1 as 3rd argument to split to account for possible trailing |||| suggested by Abigail

Replies are listed 'Best First'.
Re: regexp, substitution and the "pipe symbol"
by Abigail-II (Bishop) on Jan 29, 2004 at 16:21 UTC
    Well, if you want to do it the long way around, do it correctly. Use a third argument to split, or lose your trailing vertical bars.

    Abigail