Perltrap
Horror stories about Perl programmer. With hints and solutions.
Home
About
Authors
Why?
rss
@perltrapcom
What does this script print?
Notice the 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?
$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.