On Jun 7, Pete Emerson said:
>I don't know about anybody else, but I would LOVE a blow by blow
>interpretation of this (by anyone). I assume q{} and qr{} are pattern
>matching, although my reference here (Nutshell) comments only briefly on q,
>not qr, is that a typo? It looks like you're setting up a regular expression
>ahead of time, and my book backs that up, but I'm losing you after you set
>the $attr. Inquiring mind(s) want to understand! Thanks.
q() and qq() are like '' and "" -- they're normal quoting operators.
qr() is a 5.005 addition to the language, that produces a pre-compiled
regular expression.
$attr = qr{
\G # where the last match left off:
\s* # any preceeding whitespace
(\w+) # the attribute name
(?:
\s* = \s* # an = with any whitespace around it
(?:
" [^"]* " | # a double-quoted string OR
' [^']* ' | # a single-quoted string OR
[^\s>]+ # non-whitespace and non-> string
)
)? # but this =value portion is optional
}x;
# this produces a string
$TAG = q{<img border=0 ismap src='/foo.gif' alt="FOO!">};
# here, we match globally, but in SCALAR CONTEXT
# this makes \G match after the match of /<\w+/ in the string $TAG
$TAG =~ /<\w+/g; # position the \G anchor after the "<img"
# now we match globally, and get all attributes
# this returns all the ()'d parts of our regex,
# which are the (\w+) parts -- the attributes
@attrs = $TAG =~ /$attr/g;
>Mynd you, møøse bites Kan be pretty nasti...
A Møøse once bit my sister ...
--
Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/
I am Marillion, the wielder of Ringril, known as Hesinaur, the Winter-Sun.
Are you a Monk? http://www.perlmonks.com/ http://forums.perlguru.com/
Perl Programmer at RiskMetrics Group, Inc. http://www.riskmetrics.com/
Acacia Fraternity, Rensselaer Chapter. Brother #734
** Manning Publications, Co, is publishing my Perl Regex book **