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

Popular posts from this blog

windows - Why does Vista not allow creation of shortcuts to "Programs" on a NonAdmin account? Not supposed to install apps from NonAdmin account? -

c++ - How do I get a multi line tooltip in MFC -

unit testing - How to mock PreferenceManager in Android? -