Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^2: my within brackets

by Bod (Parson)
on Oct 14, 2021 at 19:33 UTC ( [id://11137539]=note: print w/replies, xml ) Need Help??


in reply to Re: my within brackets
in thread my within brackets

it's explicitly documented

I had looked at the docs for my and didn't find it very explicit at all. It says "If more than one variable is listed, the list must be placed in parentheses" but makes no reference to having the my statement inside the parenthesis. Or am I missing something subtle in the documentation?

This declaration seems unusual and I don't recall seeing it anywhere else which is why it stood out.

Replies are listed 'Best First'.
Re^3: my within brackets
by LanX (Saint) on Oct 14, 2021 at 19:42 UTC
    this

    > "If more than one variable is listed, the list must be placed in parentheses"

    means:

    If VARLIST is

    $x,$y,$z

    you must write

    my ($x,$y,$z)

    The alternative

    my $x,$y,$z

    would only declare $x because of precedence, like

    (my $x),$y,$z

    Hence an alternative to what we want is

    my $x,my $y,my $z

    But since we need a list assignment on the LHS, we still need to put it all into parens

    (my $x,my $y,my $z) = split ...

    because this

    my $x,my $y,my $z = split ...

    would only assign to $z because of precedence°, like

    (my $x),(my $y),(my $z = split ...)

    HTH! :)

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery

    Errata

    s/declare/assign to/ choroba++

    UPDATES

    °) Even worse, it would only be a scalar assignment to $z, i.e. the number of possible splits.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (2)
As of 2024-04-25 06:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found