regex - What is the scope of $1 through $9 in Perl? -
What is
$ 9
in Pearl via
$ 1
? For example, in this code:
sub bla {my $ x = shift; $ X = ~ s / (\ d *) / $ 1 $ 1 /; Return $ x; } My $ y; # Some codes that are $ y $ y = ~ / (\ w *) \ s + (\ w *) /; My $ z = & amp; Bla ($ 2); My $ w = $ 1; Print "$ 1 $ 2 \ n";
$ 1
What will happen? Will it be from the first \ w *
to $ x
or the first \ d *
second \ w *
$ X
?
to
numbered matching variables ($ 1, $ 2, $ 3, etc.) and related punctuation sets ($ +, $ & $ $, $ ', and $ ^ N) are dumped till the end of all dynamically engraved blocks or until the next successful match, Whichever comes first (see "Compound Statements" in "Perlsin.)"
This means that for the first time you run a rijks or a replacement in a square, a new copy is made is If the binder ends, the original value is restored (& agrave; la local)
but I do not use the regex variable outside, 20 after regex, 20 after regex, and 10 Then until $ 1
will be 10. I think the substitution seems to be more pronounced in saying things like
#! / Usr / bin / perl; Use warnings; sub bla {my $ x = shift; $ X = ~ s / (\ d *) / $ 1 $ 1 /; return $ x;} my $ y = "10 20"; mine ($ before , $ Sec) = $ y = ~ / (\ w *) \ s + (\ w *) /; My $ z = & amp; Bla ($ sec); My $ w = $ first; Print "$ first $ sec \ n";
Where are the better names of $ first
and $ second
that describe their content.
Comments
Post a Comment