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). -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/