What does this script print?
#!/usr/bin/perl use strict; $a = 1; $b = 2; $c = 3; print $a+$b+$c, "\n";
use strict statement.
It’s definetely not good to use variables without declaring them.
There are 3 undeclared variables in the script. Of course, it doesn’t work! But where exactly does it fail?
>perl abc.pl Global symbol "$c" requires explicit package name at abc.pl line 7. Global symbol "$c" requires explicit package name at abc.pl line 9. Execution of abc.pl aborted due to compilation errors.
$b are always declared global variables
intended for use in
They always present in any package and don’t break
compilation even when
use strict is in effect.
So the first undeclared variable is in fact
Resume: always do
declare your variables with
otherwise you’ll be sorry ;)
$b outside of
comparison function for
sort is a bad idea.