Now I'm starting to wonder if your assertions can be taken at face value. However, in fairness, maybe I'm just missing the point(s).

Nonetheless:

On my "unix-like" system (Ubuntu 10.4, perl 5.10.1), :

~$ perl -e '$_="qwerty"; s/r/print pos(). "\n";/e; print $_;' 3 qwe1ty

And your latest code (third block in ), modified (a) to actually do something with $*& (i.e. print it); (b) to be more explicit; and (c) to produce readable output under Ubuntu, looks like line 1 below and produces the output in lines 2-4:

perl -e "\$_='qwerty'; s/r/print pos(). \"\n\";print \$&.\"\n\";/e; pr +int \$_ . \"\n\";" 3 r qwe1ty ~$

(See also ikegami's Re^4: Using pos() inside regexp (no /e).)

or, looking at the issue through the mechanism of a script, executed in the Gnome terminal OR bash:

#!/usr/bin/perl use strict; use warnings; use feature qw(say); # perl -le "\$_='qwerty';s/r/print pos()/e;" my $str ='qwerty'; $str =~ s/[rq]/say pos($str); say $&;/eg; print "\t\$str: $str \n\n"; my $str0 ='qwerty'; $str0 =~ s/(r|q)/say pos($str0); say $&;/eg; print "\t\$str0: $str0 \n\n"; my $str1 ='qwerty'; $str1 =~ s/[rz]/say pos($str0); say $&;/eg; print "\t\$str1: $str1 \n\n"; my $str2 ='qwerty_erk'; $str2 =~ s/r/say pos($str2); say $&;/eg; print "\t\$str2: $str2 \n\n"; my $var='four'; $var =~ s/[fu]/say pos($var); say $&;/eg; print $var . "\n\n";

I don't think execution of the code above supports your interpretation of the appearance of the number 1 in the output:

~/pl_test$ perl braveghost.pl 0 q 3 r $str: 1we1ty 0 q 3 r $str0: 1we1ty Use of uninitialized value in say at braveghost.pl line 17. r $str1: qwe1ty 3 r 8 r $str2: qwe1ty_e1k 0 f 2 u 1o1r ~/pl_test$

Does your statement that "1(one) is returned by print function and s/// insert it because it is last return at executed section" mean you believe that invoking print in the regex somehow assigns its return value to pos()?

BTW, re "macos" -- "Mac OS" is the Apple TM style.


In reply to Re^11: Using pos() inside regexp (no /e) by ww
in thread Using pos() inside regexp by braveghost

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.