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.
|