<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;"><div id="yiv466544630">The variables get set the same either way.&nbsp; The difference is that shift changes the value of @_, and the other way does not.<br><br><br>--- On <b>Fri, 8/29/08, Alex Beamish <i>&lt;talexb@gmail.com&gt;</i></b> wrote:<br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;">From: Alex Beamish &lt;talexb@gmail.com&gt;<br>Subject: [tpm] Pub discussion (1)<br>To: "tpm" &lt;tpm@to.pm.org&gt;<br>Received: Friday, August 29, 2008, 3:46 AM<br><br><pre>Greetings,<br><br>After Madison's presentation on Net::DBus tonight, we retreated to<br>Burgundy's where a number of interesting technical discussions popped<br>up. Among them were discussions as to whether<br><br>    my $self = shift;<br>    my $value = shift;<br><br>would mean changes to $self would be reflected the same way than if<br>$self and
 $value were collected in<br> one fell swoop using<br><br>    my ( $self, $value ) = @_;<br><br>My experiments consisted of three files, Obj1.pm:<br><br>package Obj1;<br><br>sub new<br>{<br>    my $class = shift;<br>    my $self = {};<br><br>    bless ( $self, $class );<br>    return ( $self );<br>}<br><br>sub add<br>{<br>    my $self = shift;<br>    my $value = shift;<br><br>    $self-&gt;{value} = $value;<br>}<br><br>sub value<br>{<br>    my $self = shift;<br>    return ( $self-&gt;{value} );<br>}<br><br>1;<br><br>And the almost identical Obj2.pm:<br><br>package Obj2;<br><br>sub new<br>{<br>    my $class = shift;<br>    my $self = {};<br><br>    bless ( $self, $class );<br>    return ( $self );<br>}<br><br>sub add<br>{<br>    my ( $self, $value ) = @_;<br><br>    $self-&gt;{value} = $value;<br>}<br><br>sub value<br>{<br>    my $self = shift;<br>    return ( $self-&gt;{value} );<br>}<br><br>1;<br><br>And finally the test script:<br><br>#!/usr/bin/perl
 -w<br>#<br>#  Test creating<br> Obj1 and Obj2 to see if methods that access arguments<br>#  differently affect whether changes propogate back to the caller.<br>#  Specifically, does<br>#<br>#    my $self = shift;<br>#    my ( $vars ) = @_;<br>#<br>#  produce a different result than<br>#<br>#    my ( $self, $vars ) = @_;<br><br>use Obj1;<br>use Obj2;<br><br>{<br>    my $obj1 = Obj1-&gt;new();<br>    $obj1-&gt;add("This is object one");<br>    print "Obj1 value is " . $obj1-&gt;value() . "\n";<br><br>    my $obj2 = Obj2-&gt;new();<br>    $obj2-&gt;add("This is object two");<br>    print "Obj2 value is " . $obj2-&gt;value() . "\n";<br>}<br><br>The resulting output of running test12.pl is<br><br>[alex@foo tpm-August2008]$ perl -w test12.pl<br>Obj1 value is This is object one<br>Obj2 value is This is object two<br><br>This suggests that both methods (two shifts, or a single pull from @_)<br>produce the same results.<br><br>Have I misunderstood, or coded
 something incorrectly? I believe<br> that<br>both approaches mean pass by reference, meaning that changes are<br>reflected.<br><br>-- <br>Alex Beamish<br>Toronto, Ontario<br>aka talexb<br>_______________________________________________<br>toronto-pm mailing list<br>toronto-pm@pm.org<br>http://mail.pm.org/mailman/listinfo/toronto-pm<br></pre></blockquote></div></td></tr></table>