http://www.perlmonks.org?node_id=11160589

vincentaxhe has asked for the wisdom of the Perl Monks concerning the following question:

test.pl as below;
my $a = "abc"; my @b = $a =~ /.(?!a)/g; #comment this line to see the output my $c = 'test'; $c =~ s///; print $c
run 'perl test.pl'; line 2 run or not, affect the rest. comment it and see for yourself.I use perl 5.38 in manjaro.

ADD:

It's beyong all expectations.

Replies are listed 'Best First'.
Re: no way it's not a bug of Perl
by Corion (Patriarch) on Jul 14, 2024 at 10:26 UTC

    See the documentation of s///:

    If the pattern evaluates to the empty string, the last successfully executed regular expression is used instead. See perlre for further explanation on these.

    In your code, s///r has the empty pattern in it.

      unexpected quantum influence
        Perhaps, but what did you expect it to do? A no-op?

        You'll find a lot of places in Perl where they decided that a code expression that doesn't do anything useful should get a special case so that it does something useful.

Re: I thought I found a bug of Perl
by eyepopslikeamosquito (Archbishop) on Jul 14, 2024 at 11:05 UTC

    vincentaxhe, I see you've edited the title of your post from "no way it's not a bug of Perl" to "I thought I found a bug of Perl" without clearly indicating you did that.

    You then hastily added the line: It's beyong all expectations [sic]

    In future, please take a bit more time and care before rushing to post, and clearly mark any updates you make after posting.

    Update: See Also

    👁️🍾👍🦟
      I wish I can delete the post, but donot know how, I'm really at my wit's end and post it, I'm trying to make clear which part is updates. check your advices, I realized the title is inappropriate, I can only pray a god to delete this post.

        > I wish I can delete the post

        From How do I change/delete my post?

        PerlMonks is a place to learn. As often happens in real life, Perl Monks learn (and often learn best) from mistakes that they and others have made. If you make a mistake in a node and then delete it, you may be saving your pride but you are also depriving your fellow Monks of the chance to learn from the mistake. Only actual duplicates, spam, and obvious trolling should be deleted.

        See also How do I compose an effective node title? which advises:

        As a general rule, refrain from changing the title of a reply node unless you're actually changing the subject ... If, after careful consideration, you decide that a mid-thread title change is appropriate, please at least retain part of the original title, including the "Re^$x:" part.

        👁️🍾👍🦟
        I wish I can delete the post,

        I wouldn't worry about it. On the contrary, your post sparked a very interesting — and important — discussion. Don't worry about the edits, either; they're not that big a deal.