Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Did I match or didn't I?

by gbarr (Monk)
on Oct 18, 2001 at 00:23 UTC ( [id://119552]=note: print w/replies, xml ) Need Help??


in reply to Did I match or didn't I?

I am assuming that you want $result to contain the contents of the ()'s if the pattern matches, but "default" otherwise. Providing the ()'s cannot return "0" or "" then you could use

my ($result)= (m[pattern(group)])[0] || "default";

The outer ()'s put the RE into a list context, then we pick off the first element, which will be the contents of the matching parens

Log In?
Username:
Password:

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

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

    No recent polls found