in reply to Re: hash substitution in regex
in thread hash substitution in regex
@x = grep {$_} @x; # drop empty entries
This will also drop the entry '0' (with/without leading/trailing whitespace). Better to grep on length:
c:\@Work\Perl>perl -wMstrict -le "my @x = ( ' foo ', ' bar', 'quz ', 'x y', ' a b c ', ' ', ' ', '', '0', ' 0', '0 ', ' 0 ', ); ;; s/^\s+|\s+$//g for @x; @x = grep length, @x; printf qq{<$_> } for @x; " <foo> <bar> <quz> <x y> <a b c> <0> <0> <0> <0>
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: hash substitution in regex
by Aldebaran (Curate) on Aug 18, 2014 at 04:29 UTC | |
by Anonymous Monk on Aug 18, 2014 at 10:13 UTC | |
by Aldebaran (Curate) on Aug 21, 2014 at 19:38 UTC |