Front page | perl.beginners |
Postings from April 2010
Re: list assignment
Thread Previous
|
Thread Next
From:
Jim Gibson
Date:
April 20, 2010 09:39
Subject:
Re: list assignment
Message ID:
C7F326A8.A1D4%JimSGibson@gmail.com
On 4/20/10 Tue Apr 20, 2010 9:25 AM, "Shawn H Corey"
<shawnhcorey@gmail.com> scribbled:
> srd wrote:
>> #!/usr/bin/env perl
>> use warnings;
>> use strict;
>> my $x= (1,2,3);
>> print $x,"\n";
>> exit(0);
>> *************************************
>> output:
>> Useless use of a constant in void context at ./try.plx line 4.
>> 3
>> *************************************
>> If we put $x=(1,2) then we get 2 without the error message.
>>
>> Can someone please explain why?
>>
>>
>
> Yes, perl places the last item in the list into the variable. That's
> why the others are "useless".
>
> Try:
>
> my $x = ( 1, 2, 'this one' );
>
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).
Thread Previous
|
Thread Next