Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re^4: Strange Occurrence in Substitution Statement

by LanX (Saint)
on May 06, 2025 at 21:08 UTC ( [id://11164969]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Strange Occurrence in Substitution Statement
in thread Strange Occurrence in Substitution Statement

I think it's simpler, the pattern isn't empty, because (?:...) is always part of the pattern. Meta characters count too.

This idiom is meant to be used as s//something/ in complicated parsing, kind of inherited from sed/awk IIRC.

You should also be aware that a genuinely empty pattern IS always matching. In your case the replacement is just invisible because empty.

So I'd rather prefer to make this explicit and self documenting

  • s/$extra// if $extra

    Nowadays I doubt there are more than a fraction of a percent of programmers knowing/using this feature.

    I'd really like to see a Perl version/feature to switch it off by default.

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    see Wikisyntax for the Monastery

  • Replies are listed 'Best First'.
    Re^5: Strange Occurrence in Substitution Statement
    by choroba (Cardinal) on May 07, 2025 at 06:38 UTC
      > I'd really like to see a Perl version/feature to switch it off by default.

      I'd love that. And introducing something like /(*PREVIOUS)/ for those who need it.

      map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
    Re^5: Strange Occurrence in Substitution Statement
    by roho (Bishop) on May 07, 2025 at 04:36 UTC
      Thanks LanX. I agree that this feature should be off by default. I think it falls into the category of being a little TOO helpful, with the side effects being very difficult to pin down. I spent days trying to isolate the cause and came up empty until posing the question here. Thanks to everyone for your help.

      "It's not how hard you work, it's how much you get done."

    Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Domain Nodelet?
    Node Status?
    node history
    Node Type: note [id://11164969]
    help
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this?Last hourOther CB clients
    Other Users?
    Others meditating upon the Monastery: (3)
    As of 2025-07-12 17:15 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found

      Notices?
      erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.