The only reliable way I know is to look for regexp magic on the SV:

$ perl -MDevel::Peek my $r = qr/foo/; my $n = 'bar'; Dump( $r ); Dump( $n ); SV = RV(0x817fb18) at 0x8152cdc REFCNT = 1 FLAGS = (PADBUSY,PADMY,ROK) RV = 0x81535dc SV = PVMG(0x816dac8) at 0x81535dc REFCNT = 1 FLAGS = (OBJECT,SMG) IV = 0 NV = 0 PV = 0 MAGIC = 0x817c1f8 MG_VIRTUAL = 0x814ee88 MG_TYPE = PERL_MAGIC_qr(r) MG_OBJ = 0x8175270 STASH = 0x81530f0 "Regexp" SV = PV(0x8153b00) at 0x815360c REFCNT = 1 FLAGS = (PADBUSY,PADMY,POK,pPOK) PV = 0x816ba88 "bar"\0 CUR = 3 LEN = 4

Unfortunately, I don't have an easy way to do that from pure-Perl code. I've also never had the need to do so.


In reply to Re: How can I tell if an object is based on a regex? by chromatic
in thread How can I tell if an object is based on a regex? by kyle

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.