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

Re: Re: Sne ding Information to Sub

by dvergin (Monsignor)
on Jun 26, 2002 at 19:13 UTC ( [id://177486]=note: print w/replies, xml ) Need Help??


in reply to Re: Sne ding Information to Sub
in thread Sending Information to Sub

This works as erasei describes:       some("Foo", @alphabet); ...but be careful. You will be tempted on another occasion to do one of the following:
some(@alphabet, "Foo"); # BAD! some("Foo", @alphabet, @alpha2); # BAD!
These fail because the first array encountered in the parameter list will gobble up all the remaining values.

So you can do    some("Foo", @alphabet); and it will work because the only array in the list is the last parameter (same rule for hashes), but some would argue that it could be the beginning of a bad habit -- because later you have to be especially alert if you add another parameter for this sub.

The option is to pass a reference to the array.

some("Foo", \@alphabet); sub some { my ($one, $alpha_aref) = @_; my $letter_b = $alpha_aref->[1]; }
Thus allowing you to pass as many arrays and hashes as you may need and mix them with scalars in any order.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (9)
As of 2024-04-18 16:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found