Home > Archive > PERL Beginners > August 2007 > a division warning
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
a division warning
|
|
| Lists User 2007-08-27, 4:02 am |
| 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 about the first warning.What's it?thanks.
| |
| Chas Owens 2007-08-27, 4:02 am |
| On 8/26/07, lists user <practicalperl@gmail.com> 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 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"'
| |
| Wagner, David --- Senior Programmer Analyst --- WG 2007-08-27, 7:23 pm |
| > -----Original Message-----
> From: lists user [mailto:practicalperl@gmail.com]=20
> Sent: Sunday, August 26, 2007 20:01
> To: beginners perl
> Subject: a division warning
>=20
> I run a perl command below,
>=20
> perl -Mstrict -Mwarnings -e 'eval {my $x=3D3;my=20
> $y=3D$x-3;$x/$y};print "hello"'
> Useless use of division (/) in void context at -e line 1.
> hello
>=20
> I'm about the first warning.What's it?thanks.
You have the division, but there is no assignment for $x/$y. So
by adding $z =3D $x/$y; , then this msg will go away.
Wags ;)
>=20
> --=20
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
> http://learn.perl.org/
>=20
>=20
>=20
****************************************
******************************
This message contains information that is confidential and proprietary to F=
edEx Freight or its affiliates. It is intended only for the recipient name=
d and for the express purpose(s) described therein. Any other use is proh=
ibited.
****************************************
******************************
|
|
|
|
|