On Sunday, May 20, 2012 at 11:09 AM, sono...@fannullone.us wrote: > Are there any differences between these two idioms if only one or zero > arguments are passed to them? > > my ($mode) = @_; > > my $mode = shift; > > If so, why would you chose one over the other? > > It seems to me that they behave exactly the same for this purpose, but maybe > there's a subtle difference that I'm not aware of. 'shift' will modify @_; assignment won't. Run this:
#! perl use strict; use warnings; use feature 'say'; use Data::Printer; sub shifter { my $var = shift; say "SHIFT"; p $var; p @_; say ''; } sub assigner { my( $var ) = @_; say "ASSIGN"; p $var; p @_; say ''; } shifter( 'foo' ); assigner( 'foo' );