in reply to Re: Regex question
in thread Regex question

but.. I'm doing a bunch of stuff IN the if based on this match... =).. so setting the var outside of the if didn't help me.

Thanks though

Replies are listed 'Best First'.
Re: Re: Re: Regex question
by Koosemose (Pilgrim) on Mar 20, 2004 at 16:30 UTC

    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