SPUG: Something to loose sleep over

Bill Alford billa at willapabay.org
Tue May 2 14:48:55 CDT 2000


Could you please post a working example of code that exihbits the behavior
you described.

One thing I noticed in an earlier version of perl, when my program got too
big, a simple print statement of a variable (eg. print "test: $x\n";)
caused different behavior in my program.  I don't know if this is what
your seeing, a small test program will show that.

Thanks,
	Bill

On Sun, 30 Apr 2000, David Waring wrote:

> Sorry about my mistake. The program was not really printing ABC but of course
> ARRAY(0x8102b84)BC. But I am afraid you are all missing the point. 
> The point is that the subroutine is behaving as if the same 
> parameters are being passed each time, when they are not. This 
> behaviour is dependent on using shift to get the values of @_ and 
> shifting all values off. Interestingly the misbehaviour can be seen 
> even if @_ is printed before the shifts. I am not talking about a bug 
> in my code. The code is good it works fine on many machines. It just 
> appears to be a bug in one installation of Perl. I am just wondering 
> if anyone can tell what might be going on in this bad version of Perl.
> 
> 
> 
> 
> 
> >Think that this line will give you what you want in terms of printing:
> >	print "array = '@{shift()}' @_\n";
> >
> >As for the weirdness you're seeing -- are you using strict? :)
> >
> >This works on both 5.6 and 5.005_03
> >
> >Here's the code.  It works with and without the $x = shift lines.
> >
> >#!/usr/bin/perl
> >
> >@A = (1..3);
> >@B = (4..6);
> >@C = (7..9);
> >
> >asubroutine(\@A,"B","C");
> >asubroutine(\@B,"E","F");
> >asubroutine(\@C,"Y","Z");
> >
> >sub asubroutine {
> >  print "array = '@{shift()}' @_\n";
> >}
> >
> >Results:
> >array = '1 2 3' B C
> >array = '4 5 6' E F
> >array = '7 8 9' Y Z
> >
> >
> >On Fri, 28 Apr 2000, David Waring wrote:
> >
> > > 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
> > >
> > > asubroutine(\@A,"B","C");
> > > asubroutine(\@D,"E","F");
> > > asubroutine(\@X,"Y","Z");
> > >
> > >
> > > sub asubroutine{
> > > 	print @_,\n";
> > > 	$x= shift @_;
> > > 	$y= shift @_;
> > > 	$z= shift @_;
> > > }
> > >
> > > RESULTS
> > > ABC
> > > ABC
> > > ABC
> > >
> > > 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
> > > ABC
> > > DEF
> > > XYZ
> > >
> > > 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
> > >
> > >
> > >
> 
> 
>  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
>      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
> 
> 


 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     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