Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Re: Getting parameters in subs

by TheHobbit (Pilgrim)
on Jun 16, 2002 at 17:33 UTC ( [id://174937]=note: print w/replies, xml ) Need Help??


in reply to Re: Getting parameters in subs
in thread Getting parameters in subs

Hi,
Sorry, but this is not exact. Doing

my ($a,$b) = @_;
you do not drop anything. Just try this:
sub test1 { my ($a) = @_; print "\$a = $a\n"; print "\@_= (",join(",",@_),")\n"; } sub test2 { my $a = shift; print "\$a = $a\n"; print "\@_= (",join(",",@_),")\n"; } test1(1,2,3,4,5,6,7); test2(1,2,3,4,5,6,7);
the call to <emph>test1</emph> prints
$a = 1 @_= (1,2,3,4,5,6,7)
while the one to <emph>test2</emph> prints:
$a = 1 @_= (2,3,4,5,6,7)

The basic difference should be obvious from the above examples: assigning @_ does not modify @_ (that is obviously consistent with standard assigement semantics), while using shift physically modify @_ </>

Cheers


Leo TheHobbit

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (1)
As of 2024-04-19 00:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found