Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Identifying if a variable is the product of a qr//

by Juerd (Abbot)
on Apr 25, 2002 at 10:46 UTC ( #161914=note: print w/ replies, xml ) Need Help??


in reply to Identifying if a variable is the product of a qr//

This is ugly, but it works. (For 99.9% of all cases - if you are able to predict a scalar reference's stringification, this will fail. :)

sub is_qr { my ($qr) = @_; return 0 unless ref $qr; return 0 if defined $$qr; # Update: added this line. return 1 if ref $qr eq 'Regexp'; return index(qr/$qr/, "$qr") == -1; }
This assumes that everything blessed into Regexp is a qr//, but if you don't trust that, just remove the "return 1" line.

- Yes, I reinvent wheels.
- Spam: Visit eurotraQ.


Comment on Re: Identifying if a variable is the product of a qr//
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (7)
As of 2014-09-23 05:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (210 votes), past polls