From brian d foy's latest article in TPJ...
What is in $x after this:
my @arr = ( 0..10 ); my $x = ( 3, 4, 5, @arr );
What about now:
my $x = ( 3, 4, 5, localtime ); # or my $x = ( 3, 4, 5 );
Assume $fh1 and $fh2 are freshly opened files with 10 lines each:
my $x = ( <$fh1>, <$fh1>, <$fh1> ); my ( $y ) = ( <$fh2> ); my $z = <$fh2>;
Okay, one more, but it's a mean one:
#!/usr/bin/perl my $x = ( 1, 3, 4..10 ); my ( $y ) = ( 1, 3, 4..10 ); my ( $z ) = ( 1, 3, 4..10 )[-1];
perl -Mstrict -MData::Dumper \ -e 'my %x = %{ eval Dumper( { a => 1, b => 2 } )}';
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?