Subroutine arguments eaten by local()'s. 
Author Message
 Subroutine arguments eaten by local()'s.

Hi,

I have run across some weird behavior in Perl in which subroutines

a whittled down version displaying the behavior.

#!/usr/local/bin/perl



sub cpath {

    local($basename) = $arg[0];
    local($dvd)      = '';
    local($cpath)    = '';

Quote:
}

Executing:

Brian> /local/u/sasbnb/bin/perl.bug
BEFORE LOCALS, Cpath Args = "basename supio base share".
AFTER  LOCALS, Cpath Args = " supio base share".

The first element of the argument array is destroyed by the local()
commands. Strangely enough, in the program I hacked this snippet out of,
the last argument was eaten. Is this a known bug? My workstation is
an HP 9000 model 715 running HP unix. Is there a newer version
available?

My version is:
Brian> perl -v

This is perl, version 4.0

$RCSfile: perl.c,v $$Revision: 4.0.1.8 $$Date: 1993/02/05 19:39:30 $
Patch level: 36

Copyright (c) 1989, 1990, 1991, Larry Wall

Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 4.0 source kit.

'Awesome program, Larry!

        Brian



Sun, 23 Nov 1997 03:00:00 GMT  
 Subroutine arguments eaten by local()'s.
:
:
: Hi,
:
: I have run across some weird behavior in Perl in which subroutines

: a whittled down version displaying the behavior.
:
: #!/usr/local/bin/perl
:
: $basename = "basename";

:

:
: sub cpath {

:     local($basename) = $arg[0];

Your problem goes away if you say

local($basename) = $_[0];

instead. For me it does, that is.

--
--
jan b schipmolder



Sun, 23 Nov 1997 03:00:00 GMT  
 Subroutine arguments eaten by local()'s.

Jan,

:
:
: Hi,
:
: I have run across some weird behavior in Perl in which subroutines

: a whittled down version displaying the behavior.
:
: #!/usr/local/bin/perl
:
: $basename = "basename";

:

:
: sub cpath {

:     local($basename) = $arg[0];

Quote:
> Your problem goes away if you say
> local($basename) = $_[0];
> instead. For me it does, that is.
> --
> jan b schipmolder


That "local($basename) = $arg[0];" line is a hangover from my


a local.

It appears that there are random perterbations (like the one you found)

at all. Even worse, my tiny demo program displayed a bug that was
different than the one I had initially seen and attempted to capture.

Thanks for looking at it.

        Brian



Mon, 24 Nov 1997 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Passing subroutine as an argument to another subroutine.

2. my perl-script eats '%'-characters

3. Perl 4 vs 5: array arguments and local()

4. New bies quest

5. New bies quest

6. Benchmark results for different subroutine argument access methods

7. @_ and subroutine arguments problem

8. passing functions as arguments to subroutines

9. arrays as subroutine arguments

10. Order of evaluation of arguments in a subroutine

11. Trouble passing arguments to subroutine

12. passing argument to a subroutine

 

 
Powered by phpBB® Forum Software