in reply to Re: Schwartzian transform deformed with impunity
in thread Schwartzian transform deformed with impunity
map { /(\d+)/; $1 }
No, that is wrong. If /(\d+)/ doesn't match then $1 will not contain valid data:
$ perl -le' use Data::Dumper; my @y = map { /(\d+)/; $1 } qw/ ab123cd ab456cd abcdefg ab789cd /; print Dumper \@y; ' $VAR1 = [ '123', '456', undef, '789' ];
Just use:
$ perl -le' use Data::Dumper; my @y = map /(\d+)/, qw/ ab123cd ab456cd abcdefg ab789cd /; print Dumper \@y; ' $VAR1 = [ '123', '456', '789' ];
The regular expression by itself will just do the right thing.
|
---|