Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Re: scalar my vs list my

by merlyn (Sage)
on Apr 27, 2001 at 01:50 UTC ( #75934=note: print w/ replies, xml ) Need Help??


in reply to Re: scalar my vs list my
in thread my $var = ''; vs. use constant VAR => '';

Hmm. Nope, you ended up with a few broken ones:

# Local variables: SCALAR,SCALAR,... my $x, $y, $z; ... my $filename = "/path/to/file", $filemode = "immolate", $opmode = "seek", $filetype = "image/gif";
Neither of those declare locally anything but the first var. You'd have to do something like:
my $x, my $y, my $z;
Just think of my as a really high precedence prefix operator that must appear before an lvalue, and you'll have the right mental model. But to figure the scalar-vs-arrayness of the rest of the expression, throw away all the my's first.

My preference is one variable per my declaration, unless it's a bunch of scalars and an optional terminating array being fed from a list (like a subroutine argument grab).

-- Randal L. Schwartz, Perl hacker


Comment on Re: Re: scalar my vs list my
Select or Download Code
Re: Re: Re: scalar my vs list my
by $code or die (Deacon) on Apr 27, 2001 at 01:56 UTC
    At the risk of straying further, its ok to do this isn't it:
    my ($filename, $filemode, $opmode, $filetype) = ("/path/file", "immolate", "seek", "image/gif");
    Ignore me: I really should get into the habbit of reading the last paragraph of peoples' posts.

    $ perldoc perldoc
      What about this unruly specimen:
      (my ($filename, my ($filemode, my ($opmode, my $filetype)))) = "/path/file", "immolate", "seek", "image/gif";
      The one thing that has bugged me about my() was the way it used to cling to the real block, and not the virtual block. As in:
      for (my $n = 0; $n < 100; $n++) { # ... (Stuff) } # ... (More Stuff) for (my $n = 0; $n < 100; $n++) { # ... (Stuff) }
      IIRC, there used to be a condition that generated an error for the second declaration. This seems to have been fixed, thankfully.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2015-07-05 20:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (68 votes), past polls