in reply to Declaring variables - is it legal to do this?

Yes, this is legal. Not very common, but legal. You could have found this out yourself by simply trying a small test. Example:

my ($name, $dept, undef, $status) = qw(one two three four); print "$name, $dept, $status\n"; __OUTPUT__ one, two, four

As you can see, the third element is lost.

Replies are listed 'Best First'.
Re: Re: Declaring variables - is it legal to do this?
by kiat (Vicar) on May 15, 2004 at 05:00 UTC
    Thanks, Belgarion! Please read my reply to japhy :)
Re: Re: Declaring variables - is it legal to do this?
by Juerd (Abbot) on May 15, 2004 at 17:05 UTC

    Not very common

    Why "Not very common"? I think it is common.

    Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }

      I believe most code uses the same methods as japhy's example above. I know I've never used the (..., undef, ...) method, but I have used the (...)[0,1,4] method many times. Granted, my experience doesn't include everyone, but I don't recall seeing the undef example in any Perl documentation, while japhy's example (if I recall correctly) is shown.

      However, as always it's just a personal opinion. :)

        I've always used:

        (my $name, my $dept, undef, my $status) = get_info();
        but I can't remember why. Did 5.00[45] allow this syntax? I guess I don't have to anymore.