On Tue, Apr 20, 2010 at 09:38:48AM -0700, Jim Gibson wrote: > On 4/20/10 Tue Apr 20, 2010 9:25 AM, "Shawn H Corey" > <shawnhco...@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).
$ 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. -- Paul Johnson - p...@pjcj.net http://www.pjcj.net -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/