Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: recursive call of current script

by haukex (Archbishop)
on Jun 21, 2022 at 11:48 UTC ( [id://11144898]=note: print w/replies, xml ) Need Help??


in reply to recursive call of current script

The for is apparently just being used as a topicalizer here. So if you rewrite the first code example in "normal" Perl, it's

if ( $sFunction =~ /test1/ ) { # ... } if ( $sFunction =~ /test2/ ) { # ... }

So then it becomes more clear that one possibility of several for rewriting the logic is the following, where one could even consider to put $sFunction =~ /test2/ into a variable to avoid invoking the regex engine twice:

if ( $sFunction =~ /test1/ || $sFunction =~ /test2/ ) { # ... if ( $sFunction =~ /test2/ ) { # ... } }

Or, assuming your regexes have something in common like these example regexes, you can even write something like:

if ( my ($num) = $sFunction =~ /test([12])/ ) { # ... if ( $num eq "2" ) { # ... } }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11144898]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (3)
As of 2024-04-24 18:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found