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

Re: list assignment

Thread Previous | Thread Next
From:
Shawn H Corey
Date:
April 20, 2010 09:25
Subject:
Re: list assignment
Message ID:
4BCDD563.2080809@gmail.com
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' );


-- 
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 | Thread Next


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