#!/usr/bin/perl
use strict;
use warnings;
use diagnostics;
if (my $x = 1) {
#
} elsif (my $x = 2) {
#
}
####
"my" variable $x masks earlier declaration in same scope at test.pl line 9 (#1) (W misc) A "my" or "our" variable has been redeclared in the current scope or statement, effectively eliminating all access to the previous instance. This is almost always a typographical error. Note that the earlier variable will still exist until the end of the scope or until all closure referents to it are destroyed.
Found = in conditional, should be == at test.pl line 9 (#2)
(W syntax) You said
if ($foo = 123)
when you meant
if ($foo == 123)
(or something like that).
####
#!/usr/bin/perl
use strict;
use warnings;
use diagnostics;
# set $x from get_num(), if it returns true value
# then do something with $x
if (my $x = get_num()) {
print $x, "\n";
} else {
print "empty\n";
}
sub get_num { 3 }
####
if ( (my $x = get_num()) >= 3 ) {
...
}
####
my $x = get_num(); # assumed to always returns a number
if ($x < 0 ) {
# negative numbers
} elsif ($x < 3) {
# less
} else {
# OK
}