SPUG: Something to loose sleep over

David Waring dwaring at nwsr.com
Fri Apr 28 03:19:50 CDT 2000

Warning this is a demonstration of a bug that only appears in certain 
installations of Perl. It is a weird bug and I am really pointing it 
out as a topic of conversation. Ignore this if you are not interested 
in really yucky stuff.

We have recently had a problem with passing parameters to a 
subroutine. It only appears on one of our many boxes that are all 
running the same version of Perl (can't remember the version but it 
is pre 5.6) All boxes are running AIX.

To paraphrase the code as closely as possible

# call a subroutine several times with different parameters


sub asubroutine{
	print @_,\n";
	$x= shift @_;
	$y= shift @_;
	$z= shift @_;


whoa thats weird the subroutine is acting like it was called three 
times with the same parameters

Now we can fix this in several ways. All of the following changes 
behaved properly an had the expected results of

1) get rid of the multiple shifts and instead grab all the incoming 
params at once as any normal person would do

($x,$y,$z) = @_;

2) forget about $z and only shift in the x y values leaving @_ with a 
single value

3) stop passing the reference in the params just pass the 'normal' scalars;

4) removing all the shifts and just printing @_
I mean how on earth can what is done later with @_ affect the values 
in it?????????

Doing #1 but then setting @_ = (); -- which should be pretty damn 
close to shifting out all the values from @_ worked normally.

The Print statement before the shifts was not important. The wrong 
values were being set for x y z anyway.

We will be reinstalling Perl on this box but does anyone have any 
idea what in the deepest bowels of Perl could be going on here????

David Waring

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
 Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/
 SUBSCRIBE/UNSUBSCRIBE: Replace "action" below by subscribe or unsubscribe
           Email to majordomo at pm.org: "action" spug-list your_address

More information about the spug-list mailing list