Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Re: Re: Regex question

by Koosemose (Pilgrim)
on Mar 20, 2004 at 16:30 UTC ( [id://338311]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: Regex question
in thread Regex question

To reiterate NetWallah's point, you won't get into the loop if the regex doesn't match, meaning that if you do get into the loop, there will be something in $1, so any code to set a default value won't be called. If you have to run what is presently in the if block regardless of rather or not the match was successful, then it probably shouldn't be an if block.

You may wish to use something along the lines of thelenm's second snippet instead, something like this:

$match = ($string =~ /foobar(...)/) ? $1 : "chiapet"; push (@array, $match); bunch of other stuff...

note the lack of the if block...

Just Another Perl Alchemist

Log In?
Username:
Password:

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

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

    No recent polls found