bradcathey has asked for the wisdom of the Perl Monks concerning the following question:
Fellow Monasterians;
I'm trying to bring old code into conformity, in particular the way I call subroutines. I'm trying to convert any instances of $somecall to somecall() preserving any passed values in parens.
while (<DATA>) { chomp; $_ =~ s/^&(\w+)([\(\)]*)/$1()/; print "$_\n"; } __DATA__ &foobar &foobar() foobar() &foobar("asdf")
which prints:
foobar() foobar() foobar() foobar()"asdf")
Close, but no cigar. So, tried:
while (<DATA>) { chomp; $_ =~ s/^(&)(\w+(\([\"\'\$\w]*\))?)(\(\))$/$2()/; print "$_\n"; }
which printed:
&foobar foobar() foobar() &foobar("asdf")
Again, close, but my &'s are back. What am I missing? Thanks!
UPDATE: Pasted in correct #2 expression (thanks davidrw)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Regex to strip, keep, or add—depending
by davidrw (Prior) on Aug 06, 2005 at 15:08 UTC | |
|
Re: Regex to strip, keep, or add—depending
by JediWizard (Deacon) on Aug 06, 2005 at 15:41 UTC | |
by bradcathey (Prior) on Aug 06, 2005 at 15:53 UTC | |
by JediWizard (Deacon) on Aug 06, 2005 at 16:08 UTC | |
|
Re: Regex to strip, keep, or add—depending
by chester (Hermit) on Aug 06, 2005 at 16:32 UTC | |
by JediWizard (Deacon) on Aug 06, 2005 at 16:46 UTC | |
by chester (Hermit) on Aug 06, 2005 at 17:27 UTC | |
by BUU (Prior) on Aug 06, 2005 at 22:50 UTC |