bradcathey has asked for the wisdom of the Perl Monks concerning the following question:
Fellow Monasterians:
Sorry for the convoluted title, but as penitence for using an "&" and no "()" in calling subroutines in my early scripts, I'm hoping to edit my code with a regular expression.
my $call = "&somesub"; $call =~ s/(&)(\w+(\([\"\w]*\))?)/$2/;
OR
my $call = "&somesub("foobar")"; $call =~ s/(&)(\w+(\([\"\w]*\))?)/$2/;
I want to end up with somesub() or somesub("foobar") respectively.
Question: How can I alter my regex to add the "()"s if they are not there, and leave them if they are? Thanks!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Regex to add text if text is missing
by crashtest (Curate) on Jun 25, 2005 at 19:23 UTC | |
|
Re: Regex to add text if text is missing
by halley (Prior) on Jun 25, 2005 at 19:03 UTC | |
|
Re: Regex to add text if text is missing
by TedPride (Priest) on Jun 25, 2005 at 20:37 UTC | |
|
Re: Regex to add text if text is missing
by sk (Curate) on Jun 25, 2005 at 18:55 UTC |