<?xml version="1.0" encoding="windows-1252"?>
<node id="998525" title="Re^2: subroutine function" created="2012-10-11 15:55:57" updated="2012-10-11 15:55:57">
<type id="11">
note</type>
<author id="757127">
tobyink</author>
<data>
<field name="doctext">
&lt;blockquote&gt;
&lt;p&gt;&lt;i&gt;&lt;c&gt;
my $left=$_[0];
my $right=$_[1];
&lt;/c&gt;&lt;/i&gt;&lt;/p&gt;
&lt;p&gt;&lt;i&gt;which is the same as&lt;/i&gt;&lt;/p&gt;
&lt;p&gt;&lt;i&gt;&lt;c&gt;
my $left = shift @_;
my $right = shift @_;
&lt;/c&gt;&lt;/i&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;It is not the same at all. The first version doesn't modify &lt;c&gt;@_&lt;/c&gt;. The second one does modify it. The difference is often very important. (For example, if you're planning on using &lt;c&gt;goto&lt;/c&gt;.)&lt;/p&gt;

&lt;code&gt;
use Test::More;
use Data::Dumper;

sub func1 {
	my $left=$_[0];
	my $right=$_[1];
	goto \&amp;Data::Dumper::Dumper;
}

sub func2 {
	my $left = shift @_;
	my $right = shift @_;
	goto \&amp;Data::Dumper::Dumper;
}

my @args = qw( a b );

# Are they the same??
is(
	func1(@args),
	func2(@args),
	"they're the same!",
);

done_testing();
&lt;/code&gt;

&lt;!-- Node text goes above. Div tags should contain sig only --&gt;
&lt;div class="pmsig"&gt;&lt;div class="pmsig-757127"&gt;
&lt;small&gt;&lt;small&gt;
&lt;tt&gt;perl -E'sub Monkey::do{say$_,for@_,do{($monkey=&amp;#x5B;caller(0)]-&gt;&amp;#x5B;3])=~s{::}{ }and$monkey}}"Monkey say"-&gt;Monkey::do'
&lt;/tt&gt;&lt;/small&gt;&lt;/small&gt;
&lt;/div&gt;&lt;/div&gt;</field>
<field name="root_node">
998515</field>
<field name="parent_node">
998517</field>
</data>
</node>
