Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Difference between my ($foo) & my $foo

by repellent (Priest)
on Feb 12, 2009 at 19:54 UTC ( #743441=note: print w/replies, xml ) Need Help??


in reply to Difference between my ($foo) & my $foo

With:
my (undef, $a, undef, $b, @rest, $c) = (1, 2, 3, 4, 5, 6, 7, 8);

Now:
  • @rest will be greedily assigned: @rest = (5, 6, 7, 8)
  • the other variables are respectively assigned: ($a, $b, $c) = (2, 4, undef)

Then:
my $count = @rest; # 4 - because there are four items (scalar contex +t) my ($first) = @rest; # 5 - because first item is 5 (list context)

But:
my $last = (11, 22, 33, 999); # 999 - because assigning LIST to scalar + only picks last item

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://743441]
help
Chatterbox?
[Corion]: LanX: But most of that is just setup of variables to be used later, like CC , LIB etc.
[LanX]: yes and some builders try to avoid it
[RonW]: :)

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2017-08-18 21:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Who is your favorite scientist and why?



























    Results (310 votes). Check out past polls.

    Notices?