Re: Safe list assignment

[email protected] ("Jeff Peng")
Newsgroups perl.beginners
Message-ID <[email protected]>
On Tue, May 27, 2008 at 6:00 PM, Ed Avis <[email protected]> wrote:
> Is there an equivalent in Perl?  Something like
>
>     safe_assign ($a, $b, $c) = @array;    # will die if scalar(@array) != 3
>

No. if @array includes 3 elements, all statements below are right in Perl:

my ($a) = @array;
my ($a,$b) = @array;
my ($a,$b,$c) = @array;
my ($a,$b,$c,$d) = @array;

in the last case, the $d will be undef.

-- 
Jeff Peng - [email protected]
Professional Squid supports in China
http://www.ChinaSquid.com/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.