Wednesday, April 4, 2007

Perl pop quiz

What's wrong with this picture:

#!/app/clarity/perl/bin/perl

use strict;
use Error qw(:try);

my $result;
try
{
print "setting result to abc\n";
$result = "abc";
} catch Error with
{
print "caught an error\n";
}

my $a = $result;
print "a=$a\n";
print "result=$result\n";

Check out the output:

[root@devin rtest]# ./quiz.pl
setting result to abc
a=
result=abc

When Dan pointed out the error after looking at it for a few minutes, I wanted to cry.

The answer, for those who might be interested, will be in tomorrow's edition of "Why Devin Hates Perl"