Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: variable declaration question

by blue_cowdawg (Monsignor)
on Jan 18, 2013 at 21:34 UTC ( #1014134=note: print w/replies, xml ) Need Help??


in reply to variable declaration question

      What's the difference between "my $var;" and "my ($var);" in variable declaration?

Strictly speaking, the way you've presented the above not much except you fingers are slightly more tired. That said consider the following code:

sub marine { my ($fore,$mid,$aft) = @_; }
In the above example I have an array on the LHS and an array on the RHS. This is equivalent to:
sub marine { my $fore = $_[0]; my $mid = $_[1]; my $aft = $_[2]; }
When coding parens, just like in written English, are used to group things together.

Clear as mud?


Peter L. Berghold -- Unix Professional
Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg

Replies are listed 'Best First'.
Re^2: variable declaration question
by muba (Priest) on Jan 18, 2013 at 22:39 UTC
    In the above example I have an array on the LHS and an array on the RHS. This is equivalent to:

    Strictly speaking... this not true. You have a list on the LHS, as per perlfaq4: What is the difference between a list and an array:

    A list is a fixed collection of scalars. An array is a variable that holds a variable collection of scalars. An array can supply its collection for list operations, so list operations also work on arrays

    ...

    Array operations, which change the scalars, rearranges them, or adds or subtracts some scalars, only work on arrays. These can't work on a list, which is fixed. Array operations include shift, unshift, push, pop, and splice.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1014134]
help
Chatterbox?
[stonecolddevin]: o/ planetscape
[Sinistral]: I think that just the sight of his username now causes a downvote storm. I agree, and the gratuitous use of formatting does make reading hard. I've given him +1 on things where there seemed to be actual good advice, but I think the big
[Sinistral]: nail in coffin was the rant against a Schwarzian Transform
[stonecolddevin]: at best, from what i've seen, his knowledge is accurate up to maybe 2002. the sheer volume of words is mostly worthy of a downvote in most cases though i think
[erix]: ITYM Schwartzian Transform :P
[erix]: hey planetscape :)
[planetscape]: howdy stonecolddevin, erix
[Sinistral]: eric Aye. I thought I typed that wrong. All hail Randall! I listen to him on FLOSS Weekly
[Discipulus]: i think his vacuus, trombon like, absence of meaning, joined with a ostentatious style, after many years irritates the most
[erix]: easy to get wrong -- I guess that was sund's point, too :P

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (10)
As of 2017-06-22 20:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many monitors do you use while coding?















    Results (530 votes). Check out past polls.