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: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.when the second line will do everything that the firstline is doing?$s =~ s/^[ \t]+//mg; # remove leading whitespace from each line $s =~ s/^\s+//; # remove leading whitespace
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.
|
|---|