in reply to Re: Pulling out an element from a function return without using an intermediate list
in thread Pulling out an element from a function return without using an intermediate list

Really?
use strict; my(undef, $aa, $bb) = dir(); Can't declare undef operator in my at (eval 159) line 2, near ") ="
  • Comment on Re^2: Pulling out an element from a function return without using an intermediate list
  • Download Code

Replies are listed 'Best First'.
Re^3: Pulling out an element from a function return without using an intermediate list
by GrandFather (Saint) on Feb 19, 2007 at 22:16 UTC
    use strict; use warnings; my (undef, $param, undef, $other, @stuff) = dir(); print "undef, $param, undef, $other, @stuff"; sub dir { return (1, 2, 3, 4, 5, 6); }

    Prints:

    undef, 2, undef, 4, 5 6

    Works fine for me. What version of Perl are you using?


    DWIM is Perl's answer to Gödel
Re^3: Pulling out an element from a function return without using an intermediate list
by ikegami (Patriarch) on Feb 19, 2007 at 22:17 UTC

    On the other hand, the following versions all work:

    my $aa; my $bb; (undef, $aa, $bb) = dir();
    my ($aa, $bb); (undef, $aa, $bb) = dir();
    (undef, my $aa, my $bb) = dir();
    (undef, my ($aa, $bb)) = dir();
    my ($aa, $bb) = ( dir() )[1, 2];

    Update: Apparently, so does the following (contrary to the parent's claims):

    my (undef, $aa, $bb) = dir();

    Tested the last one on Perl 5.6.0, 5.6.1, 5.8.0 and 5.8.8.

Re^3: Pulling out an element from a function return without using an intermediate list
by Joost (Canon) on Feb 19, 2007 at 22:36 UTC