in reply to How to delete trailing spaces from array elements?

Hi,

Just one more way to do the same :)

@arr1 = map{ (s/\s*$//)&&$_}@arr1;

Cheers !

--VC



There are three sides to any argument.....
your side, my side and the right side.

Replies are listed 'Best First'.
Re^2: How to delete trailing spaces from array elements?
by ikegami (Patriarch) on Jul 31, 2007 at 15:13 UTC
    The asignment is unnecssary since you've already modified @arr1 by modifying $_.
    use List::MoreUtils qw( apply ); @array = apply { s/\s+\z// } @array;

    or

    map { s/\s+\z// } @array;

    or

    s/\s+\z// for @array;

      if you don't want to dig into regular expressions (that funny /\s+$//gms stuff) yourself, you might try this approach:

      use Text::Trim; my @strings2trim = ("yo ", " boo"); trim(@strings2trim);