Bowen, Bruce wrote:
> In perldoc under this topic s is listed as "Treat string as a single
> line" and m as Treat string as multiples lines".
>
> If I have text that has varying spaces at the begging of each line,
> and I use
>
> $string =~ s/^\s+//; It will remove the spaces from in from of the
> first line but not any other lines. That is clear to me.
>
> However, it does not clear all of the leading spaces from all of the
> lines if I use
>
> $string =~ m/^\s+//;
>
> In fact I'm getting error message compile error. What am I missing
> here?
perldoc perlop
[snip]
m/PATTERN/cgimosx
^ ^ ^
[snip]
s/PATTERN/REPLACEMENT/egimosx
^ ^ ^
The /s option affects the behaviour of the . meta-character. The /m option
affects the behaviour of the ^ and $ meta-characters.
Assuming you have the string:
my $string = "one\n two\n three\nfour\n five\n";
$string =~ s/.+//;
Will produce the string:
"\n two\n three\nfour\n five\n"
And:
$string =~ s/.+//g;
Will produce the string:
"\n\n\n\n\n"
While:
$string =~ s/.+//s;
Will produce the string:
""
$string =~ s/^\s+//;
Will produce the string:
"one\n two\n three\nfour\n five\n"
(It isn't modified.)
While:
$string =~ s/^\s+//m;
Will produce the string:
"one\ntwo\n three\nfour\n five\n"
(Only the first match is changed.)
And:
$string =~ s/^\s+//mg;
Will produce the string:
"one\ntwo\nthree\nfour\nfive\n"
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>