Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re^3: Contextual find and replace large config file

by haukex (Bishop)
on Jan 03, 2019 at 12:40 UTC ( #1227979=note: print w/replies, xml ) Need Help??

in reply to Re^2: Contextual find and replace large config file
in thread Contextual find and replace large config file

Why (?:\z|\n) and not just \z when \z is 'up to and including \n'

Not quite, \z only ever matches at the very end of the string, whereas \Z also matches before the newline at the end of the string, and the meaning of $ is changed by the /m modifier to match before every newline or at the end of the string. When I want to express "match up to the end of this line", I sometimes prefer (?:\z|\n) over $+/m because the former explicitly consumes the \n.

Why \h*\n* and not \s*

Because /\s*/ would also match e.g. \t\n\t, which causes a following /^.../ to no longer match, since /\s*/ consumed the \t at the beginning of the line.

Update: Regarding the first point:

$ perl -MData::Dump -e 'dd split /($)/m, "x\ny\nz"' ("x", "", "\ny", "", "\nz") $ perl -MData::Dump -e 'dd split /(\z|\n)/m, "x\ny\nz"' ("x", "\n", "y", "\n", "z")

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (1)
As of 2021-09-20 03:22 GMT
Find Nodes?
    Voting Booth?

    No recent polls found