Saturday, June 4, 2005

Advanced Perl Programming, 2nd Edition - Contest 1

The broken code for the first contest can be found below. In the code, the hash { a => 1, b => 2 } is being passed through Data::Dumper and then eval'ed back into a hash. This works fine, until strict comes into the picture. When strictness is enabled, the code fails with the error: "Can't use an undefined value as a HASH reference". How can you make this work and still keep strictness for all of the code.


perl -Mstrict -MData::Dumper -e 'my %x = %{eval Dumper({ a => 1, b => 2 })}';


Email perlcast at gmail dot com the answer to this, along with the comment that I mentioned in Perlcast 12 and you will be entered into the contest drawing. The deadline for entry is this Friday at noon CST (2005-06-10 12:00:00 UTC-5).