develooper Front page | perl.beginners | Postings from April 2010

Re: list assignment

Thread Previous
From:
Shawn H Corey
Date:
April 21, 2010 05:30
Subject:
Re: list assignment
Message ID:
4BCEEFBD.8050901@gmail.com
srd wrote:
> What really needs an explanation is if the array contains n elements
> then (n-2) warnings are emitted.
> maybe i was not so clear about my question


Paul Johnson wrote:
 > On Tue, Apr 20, 2010 at 09:38:48AM -0700, Jim Gibson wrote:
 >> Yes, but as srd has observed, you get one fewer warning message than 
there
 >> are "useless" items. Try:
 >>
 >> my $x = ( 1, 2 );
 >>
 >> and you get no warnings. Try:
 >>
 >> my $x = ( 1, 2, 3, 4 );
 >>
 >> and you get 2 warnings. One of those "useless" items isn't useless 
(or Perl
 >> just doesn't care).
 >
 > $ perl -Mdiagnostics -we 'my $x = (1,2,3)'
 >
 > will explain that 0 and 1 are treated specially.
 >
 > Using the newly released perl-5.12.0 will even tell you which of the
 > constants are useless.
 >

0 and 1 are special in that they don't generate the warning.  For 
example, the assignment to $z is the only line with warnings:

#!/usr/bin/perl

use strict;
use warnings;

my $x = ( 0, 0, 0, 0, 0, 0, 0, 7 );
my $y = ( 1, 1, 1, 1, 1, 1, 1, 7 );
my $z = ( 2, 2, 2, 2, 2, 2, 2, 7 );

__END__


-- 
Just my 0.00000002 million dollars worth,
   Shawn

Programming is as much about organization and communication
as it is about coding.

I like Perl; it's the only language where you can bless your
thingy.

Eliminate software piracy:  use only FLOSS.

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About