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

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
So I'll take a stab at this, and maybe I'm missing what you're asking.

If you bless in a regular expression, it becomes a SCALAR, and as far as I can tell, there's no way to come up with the direct reference of it again, without putting it into regular expression context, like you have (but the only way I can see to do that is to actually use it). Then perl's internal magic kicks in, and blammo, it works.

However, this code below, works to determine whether a blessed thingy is a regexp:
#!/usr/bin/perl -w use strict; use warnings; use Data::Dumper; my $rex = qr/[A-Z]o[A-Z]/; my $bar = \$rex; #my $blessed = bless qr/[A-Z]o[A-Z]/,'foo'; my $blessed = bless $bar, 'foo'; $\="\n"; $,=":\t"; print "Rex ",ref $rex; print "Bless",ref $blessed; print "Rex ",$rex,"WoW"=~$rex ? "WoW" : "---"; print "Bless",$blessed,"WoW"=~$$blessed ? "WoW" : "---"; print "Rex ",$rex,"wow"=~$rex ? "!WoW" : "---"; print "Bless",$blessed,"wow"=~$$blessed ? "!WoW" : "---"; print "Rex ",Dumper($rex); print "Bless",Dumper($blessed); print "Blessed bar", ref $$blessed;
lends me back:
Rex : Regexp Bless: foo Rex : (?-xism:[A-Z]o[A-Z]): WoW Bless: foo=SCALAR(0x80fd428): WoW Rex : (?-xism:[A-Z]o[A-Z]): --- Bless: foo=SCALAR(0x80fd428): --- Rex : $VAR1 = qr/(?-xism:[A-Z]o[A-Z])/; Bless: $VAR1 = bless( do{\(my $o = qr/(?-xism:[A-Z]o[A-Z])/)}, 'foo' +); Blessed bar: Regexp


So you can work around it, by blessing references to references in, thus making the internal reference type of 'ref' and then maybe you don't have that layer of blessed magic-ness to work around. Is it because there is no way to put a scalar in regexp context without actually running it?

    --jb

In reply to Re: Identifying if a variable is the product of a qr// by JayBonci
in thread Identifying if a variable is the product of a qr// by demerphq

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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others chanting in the Monastery: (6)
    As of 2014-11-27 20:07 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My preferred Perl binaries come from:














      Results (187 votes), past polls