I started playing with the perl debugger and I still think I am right though I do not quite know the reasoning behind it. The debugging went as follows ( I am omitting much, but leaving the important parts). First the program:
use strict; use warnings; my $test = "fee fi fo free"; if ($test =~ m!((??{ substr($test,0,$_) }))!) {};
Now the debugging stuff:
DB<1> V main # $_ never appears after this command DB<2> s main::(bah4.pl:6): if ($test =~ m!((??{ substr($test,0,$_) }))!) +{}; DB<2> V main # $_ never appears after this command DB<3> s main::((reeval 2)[bah4.pl:6]:1): DB<3> V main #At this point again variables in main are #listed there is a line: # $_ = 'fee fi fo free' DB<4> s Argument "fee fi fo free" isn't numeric in substr at (reeval 2)[bah4.p +l:6] line 1.
and then a bunch of error stuff. I ran the one liner through the debugger and $_ never gets set, but as I mentioned before I do not know why the difference, perchance one of the many wiser monks than I might enlighten us at this point.

-enlil

*Note: I have not used the debugger all the much, so if I managed to confuse myself and thereby gave out misinformation let me know.


In reply to Re: Re: Re: Troubles with m!(??{substr(...)})! by Enlil
in thread Troubles with m!(??{substr(...)})! by jens

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.