On 3/8/06, Eugeny Altshuler <[EMAIL PROTECTED]> wrote:
snip
> local $/; # to slurp the file at once
> my $joined=<>;
snip
> What '\s*=\s*(["']).*?\1' mean?
Be careful with the setting of $/. In small scripts like this one it
is not very dangerous, but in larger scripts in can cause all manner
of bugs if not properly localized:
my $joined;
{
local $/ = undef;
$joined = <>;
}
or better yet, don't use slurp mode at all:
my $joined = join '', <>;
s,STYLE\s*=\s*([" ']).*?\1,,igs; means
replace in the entire string ignoring newlines as many times as it
appears in a case insensitive manner "STYLE" followed by zero or more
whitespace characters followed by "=" followed by zero or more
whitespace characters followed by either ' or " followed by zero or
more characters (non-greedy) followed by the matching ' or " with
nothing
I would have written it like this
s{ #replace
STYLE #the word "style" (case insensitive)
\s* #followed by zero or more whitespace characters
= #followed by the equal sign
\s* #followed by zero or more whitespace characters
("|') #followed by a quote (either " or ', remember the type)
.*? #followed by the shortest number of characters
\1 #followed by the match quote from above
}{ #with
#nothing
}igsx;
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>