I just realised that since the addition of /r, you can now write s!!!regex. Or s!!!regexp if you prefer.
/r
s!!!regex
s!!!regexp
Finally a use for the /r modifier.
Well, this is quite pretty:
my @new = map { s/foo/bar/r } @old;
Compared with the old way:
my @new = map { (my $tmp = $_) =~ s/foo/bar/; $tmp } @old;
map { s/foo/bar/ } (my @new = @old); or my @new; map { s/foo/bar/ } (@new = @old); works fine too
map { s/foo/bar/ } (my @new = @old);
my @new; map { s/foo/bar/ } (@new = @old);
The problem with /r is that it should really be r// not s//r, Things that are different should look different.
my @new = map { s/foo/bar/; $_ } @{[@old]}; is also an option, though not a terribly pretty one.
my @new = map { s/foo/bar/; $_ } @{[@old]};
and for those who dislike map in void context: s/foo/bar/ for (my @new = @old);
s/foo/bar/ for (my @new = @old);
Waxing philosophical
Finally a use for the /r modifier.
Well, this is quite pretty:
Compared with the old way:
map { s/foo/bar/ } (my @new = @old);
ormy @new; map { s/foo/bar/ } (@new = @old);
works fine tooThe problem with /r is that it should really be r// not s//r, Things that are different should look different.
my @new = map { s/foo/bar/; $_ } @{[@old]};
is also an option, though not a terribly pretty one.and for those who dislike map in void context:
s/foo/bar/ for (my @new = @old);