FAQ
Hi there,

Allow me to correct myself, the value of the assignment is the new value of the variable. But in the end it is the same. The compiler won't be able to see what $bar is when used in if ($foo=$bar), therefore won't throw any warnings.

Cheers,
Jing
On 15 Aug 2013, at 01:21, Alexey Mishustin wrote:

Hello all,

If I make a typo and write a single "equals" operator here:

#!/usr/bin/perl

use strict;
use warnings;

my $foo = 1;
my $bar = 2;

if ($foo = 2) {
print "yes\n";
}
else {
print "no\n";
}

...then the "warnings" pragma works OK and tells me "Found = in
conditional, should be ==..."

But if I make the same typo and write a single "equals" operator there:

#!/usr/bin/perl

use strict;
use warnings;

my $foo = 1;
my $bar = 2;

if ($foo = $bar) {
print "yes\n";
}
else {
print "no\n";
}

... then I get no warning; the script output is "yes".

Why is it so?

How could I catch such typos?

--
Regards,
Alex

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 3 of 14 | next ›
Discussion Overview
groupbeginners @
categoriesperl
postedAug 14, '13 at 5:22p
activeAug 15, '13 at 6:02a
posts14
users6
websiteperl.org

People

Translate

site design / logo © 2022 Grokbase