Perl 5.001e subroutine returns length of array instead of array 
Author Message
 Perl 5.001e subroutine returns length of array instead of array

Here is the offending program, distilled down just to show the problem.
This example works fine in perl4.36 and perl5.000, but fails in perl5.001e.
--------------------------------------------------
#!/usr/local/perl
&trace("This is Perl Version $]");
&toplevel();

sub toplevel {



Quote:
}

sub doa1 {

    $level++;
    &trace("Entering doa1, 'wantarray' is ", wantarray);

    while (1) {
        if (!defined($recursive)) {
            $recursive = 1;
            &trace("doa1 recurse");



            next;
        } else {

            $level--;

        }
    }

Quote:
}

# print a message.
sub trace {

Quote:
}

--------------------------------------------------
Here are the results running under perl5.000 and perl5.001e.  Note that
perl4 gives the same correct result as perl 5.000.
--------------------
thor% perl5.000 arrarybug
This is Perl Version 5.000
   Entering doa1, 'wantarray' is  1
   doa1 recurse
      Entering doa1, 'wantarray' is  1
      returning from doa1 with  5 lines
   Subroutine returned '7 8 9 10 11'
   returning from doa1 with  10 lines
Subroutine returned '7 8 9 10 11 7 8 9 10 11'
--------------------
thor% perl5.001 arraybug
This is Perl Version 5.001
   Entering doa1, 'wantarray' is  1
   doa1 recurse
      Entering doa1, 'wantarray' is  1
      returning from doa1 with  5 lines
   Subroutine returned '5'
   returning from doa1 with  6 lines
Subroutine returned '6'
--------------------

The problem seems to be that the "return" is not interpreting the array

returns '99 88 5' and  '99 88 8' for the two calls, indicating that the
subroutine's return value is properly interpreted in an array context, but
somehow "return" isn't evaluating its argument list properly.

Additional notes:
    It doesn't seem to matter if the array is a named array or a function
    returning an array, it breaks in either case.  I tried replacing

    change in results.

    It works if we return a REFERENCE to an array, but we wanted the
    program to be able to run under perl4.

        pete peterson

        (508)287-7478; Home: (508)256-5829 (Chelmsford, MA)



Sun, 02 Nov 1997 03:00:00 GMT  
 Perl 5.001e subroutine returns length of array instead of array

Quote:
>Here is the offending program, distilled down just to show the problem.

You can distill it down a lot further:

    sub foo {
        while(1)
        {
            {


            }
        }
    }
    print &foo, "\n";

In perl5.000, this prints 2358, as it should; in 5.001e it prints 4.

--
HansM



Mon, 03 Nov 1997 03:00:00 GMT  
 Perl 5.001e subroutine returns length of array instead of array

Quote:


> >Here is the offending program, distilled down just to show the problem.

> You can distill it down a lot further:


>             }
>         }
>     }

> In perl5.000, this prints 2358, as it should; in 5.001e it prints 4.

This is a known bug that has been reported in other guises before.

Quote:
> HansM

Tim.


Tue, 04 Nov 1997 03:00:00 GMT  
 Perl 5.001e subroutine returns length of array instead of array

Quote:

> You can distill it down a lot further:
>     sub foo {
>     while(1)
>     {
>         {


>         }
>     }
>     }
>     print &foo, "\n";
> In perl5.000, this prints 2358, as it should; in 5.001e it prints 4.

But even better, if you


you get 14 !
--

"When the only tool you have is Perl, the whole | "Hooray for snakes!"
 world begins to look like your oyster." -- Me  |  -- The Simpsons (29 Apr 93)
============== And remember, you heard it first on Usenet News ===============



Mon, 10 Nov 1997 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. returning an array of arrays from a subroutine

2. Perl 5 arrays of arrays, length of etc..

3. Variable length array of arrays into tree structure - help

4. Efficiency/New Perl Book: return @array vs \@array

5. Efficiency/New Perl Book: return @array vs \@array?

6. Return Array from a Nested Subroutine?

7. recursion, array returning subroutine, dump core on SGI

8. Subroutines Returning Null Arrays

9. returning arrays from a subroutine

10. Returning hashes of arrays from a subroutine

11. Returning hash of arrays in a subroutine

12. Returning Local array from Subroutine?

 

 
Powered by phpBB® Forum Software