Inline regex replacement in perl -
is there way replace text regex inline, rather taking text variable , storing in variable?
i'm perl beginner. find myself writing
my $foo = $bar; $foo =~ s/regex/replacement/; dostuff($foo)
where i'd write
dostuff($bar->replace(s/regex/replacement/));
or like, rather using temporary variable , 3 lines.
is there way this? when regex sufficiently complicated makes sense split out can better explained, when it's s/\s//g
feels wrong clutter code additional variables.
starting perl 5.14 can use non-destructive substitution achieve desired behavior.
use /r
modifier so:
dostuff($bar=~s/regex/replacement/r);
Comments
Post a Comment