All entries


06 Nov 2013
Эта же задача по-русски: здесь.

What does this script print?


use strict;

$a = 1;
$b = 2;
$c = 3;

print $a+$b+$c, "\n";



Notice the use strict statement.

Hint 2


It’s definetely not good to use variables without declaring them.

Hint 3


There are 3 undeclared variables in the script. Of course, it doesn’t work! But where exactly does it fail?

Hint 4


Global symbol "$c" requires explicit package name at line 7.
Global symbol "$c" requires explicit package name at line 9.
Execution of aborted due to compilation errors.



$a and $b are always declared global variables intended for use in sort function. 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 $c.

Resume: always do use strict, declare your variables with my or our, otherwise you’ll be sorry ;) And using $a and $b outside of comparison function for sort is a bad idea.