Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^3: $1[ (or "Does an array @1 exist in Perl ? - Yes!")

by hippo (Bishop)
on Oct 11, 2017 at 15:14 UTC ( [id://1201169]=note: print w/replies, xml ) Need Help??


in reply to Re^2: $1[ (or "Does an array @1 exist in Perl ? - Yes!")
in thread $1[

One can use "$1[$2]$3[$4]$5" expecting no array (with impossible names according doc) interpretation.

No, the documentation does not say they are impossible at all:

Perl variable names may also be a sequence of digits, a single punctuation character, or the two-character sequence: ^ (caret or CIRCUMFLEX ACCENT) followed by any one of the characters [][A-Z^_?\] . These names are all reserved for special uses by Perl; for example, the all-digits names are used to hold data captured by backreferences after a regular expression match.

So @1, @2, @1066, etc. are all perfectly valid. They are just reserved for special uses by Perl.

Replies are listed 'Best First'.
Re^4: $1[ (reserved != allowed)
by LanX (Saint) on Oct 11, 2017 at 15:31 UTC
    One can reserve @1 , but the parser should croak or at least warn as long as the reservation wasn't filled with meaning.

    I think %+ and %- are good examples of taking advantage of reserved variables after introducing named captures in regex. ( added in Perl v5.10.0)

    @1 has no special meaning and doesn't need to be declared under strict!

    As a side note, it's possible to use @a or %b without explicit declaration under strict ... that's really not optimal and really should be documented.

    Cheers Rolf
    (addicted to the Perl Programming Language and ☆☆☆☆ :)
    Je suis Charlie!

      By the way, today I've found that in Modern_Perl book, as an example is given @3 as incorrect name:
      These are invalid Perl identifiers: my $invalid name; # space is invalid my @3; # cannot start with number my %~flags; # symbols invalid in name
      (from 4th edition, page #13)
        > in Modern_Perl book, as an example is given @3 as incorrect name:
        These are invalid Perl identifiers: ... my @3; # cannot start with number

        Which is correct, cause my declares a lexical var, no exceptions needed there

        DB<475> my @3 =(1,2,3) Can't use global @3 in "my" at (eval 679)[C:/Perl_64/lib/perl5db.pl:64 +6] line 2, ...

        Cheers Rolf
        (addicted to the Perl Programming Language and ☆☆☆☆ :)
        Je suis Charlie!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1201169]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2024-04-16 13:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found