Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^2: Removing multiple trailing comment lines from a string

by eyepopslikeamosquito (Archbishop)
on Dec 23, 2016 at 09:38 UTC ( [id://1178423]=note: print w/replies, xml ) Need Help??


in reply to Re: Removing multiple trailing comment lines from a string
in thread Removing multiple trailing comment lines from a string

Why would you need this:
$s =~ s/^[ \t]+//mg; # remove leading whitespace from each line $s =~ s/^\s+//; # remove leading whitespace
when the second line will do everything that the firstline is doing?
Remember that $s is a multi-line string. So the regex mg modifier in the first regex above ensures that each line in the multi-line string has leading spaces and tabs removed from it.

The second regex, OTOH, does not have any modifiers, so it does not apply to every line in the multi-line string; instead, it trims leading whitespace (this time, including newlines) from the front of the multiline string -- trimming multiple blank lines from the front of a multi-line string, for example.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (2)
As of 2024-04-26 05:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found