On 8/26/07, lists user <[EMAIL PROTECTED]> wrote: > I run a perl command below, > > perl -Mstrict -Mwarnings -e 'eval {my $x=3;my $y=$x-3;$x/$y};print "hello"' > Useless use of division (/) in void context at -e line 1. > hello > > I'm confused about the first warning.What's it?thanks.
Let's break this down and see what is going on: perl -MO=Deparse -Mstrict -Mwarnings -e 'eval {my $x=3;my $y=$x-3;$x/$y};print "hello"' Useless use of division (/) in void context at -e line 1. use warnings; use strict 'refs'; eval { do { my $x = 3; my $y = $x - 3; $x / $y } }; print 'hello'; -e syntax OK >From this we can see that the result of $x/$y is not used. Perl is warning you that this is "useless". However, it is not exactly useless as it is triggering a divide by zero error in the eval. The way to get rid of this warning is to make sure the result is used by a function or assigned to a variable: perl -Mstrict -Mwarnings -e 'eval {my $x=3;my $y=$x-3; my $z = $x/$y};print "hello"' -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/