"tried using a 'ref $re', looking for a Regexp" means I tried using 'ref' on '$re' and expected to get a RegExp, but didn't, as in:
my %hash=(qr{([0-4])}=>"foo", a=>"foo2"); $_=2; for my $re (keys %hash) { P "re=%s, ref=%s", $re, ref $re; P "match:(%s) %s", $1, $hash{$re} if /$re/; } ' re=a, ref= re=(?^:([0-4])), ref= match:(2) foo
In the case that matches where "re=(?^:(0-4))", the ref was blank. I felt this was confusing -- since if you first assign the "qr" expression to a scalar and check the ref, you do get a ref of Regexp. But if you put it directly into the hash and do a ref on the key you pull out, the ref-type is lost. After the qr-expression has been used as a key in a hash, you lose the reference. At that point, determining that it was a Regexp, is a bit "unpretty", in that it seems one would test if the expression began with '(?'.

Also, the '^' being inserted after '(?' looks odd since the original 'qr' expression didn't include it. Do you know why it was inserted in the stringified version?

At this point, to check whether or not I need to use the 'key' directly or use it in a RE it seems I look for the paren, question-mark, which just looks strange, even though it works.


In reply to Re^4: how to use string RE (against $_ and capture) by perl-diddler
in thread how to use string RE (against $_ and capture) by perl-diddler

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.