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

Re^3: In place replacement from reference list

by AnomalousMonk (Archbishop)
on Sep 07, 2022 at 20:01 UTC ( [id://11146749]=note: print w/replies, xml ) Need Help??


in reply to Re^2: In place replacement from reference list
in thread In place replacement from reference list

=~ m/^$path1|$path2|...etc/

I know LanX and kcott understand this, but here's a general side note. In a regex expression like the one quoted above, the ^ anchor is associated only with the first alternation, i.e., ^$path1. None of the other alternations are anchored.

The "precedence" of Perl ordered alternation is very low. This applies generally, so in
    $str =~ m/ a b c | d | e | f g h /x;
the regex pattern "atoms" a b c comprise the first possible alternation, then d if the first alternation cannot match, then e, then the f g h sequence.

Use grouping, typically non-capturing, to disambiguate precedence. E.g., in
    $str =~ m/ a b (?: c | d e | ... | etc) f g /x;
the sequence a b is required for a match, then the first of c or d e or ... or etc, then the required f g sequence.


Give a man a fish:  <%-{-{-{-<

Replies are listed 'Best First'.
Re^4: In place replacement from reference list
by LanX (Saint) on Sep 07, 2022 at 21:00 UTC
    I didn't think about that, it wasn't meant to be productive code just an illustration.

    Thanks for pointing that out! :)

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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2024-03-29 08:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found