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