[Raleigh-talk] life without use strict

Trevor Little trevormg19 at gmail.com
Wed Feb 11 14:11:39 PST 2009


Consider the following code:

   1 #!/usr/bin/perl
   2
   3 #NOPE!#use strict;
   4
   5 my $var;
   6 $var = 1;
   7 $var->{key} = '123456789';
   8
   9 print $var        . "\n";
  10 print $var->{key} . "\n";


After line 7, does $var hold a hashref, or the number 1? If you turn back  
on use strict, you get the following error:

  Can't use string ("1") as a HASH ref while "strict refs" in use at  
creepy.pl line 7.

So it looks like perl is storing the number 1, but with strict off the  
output is:

  1
  123456789

What's going on here? I'm running perl 5.8.8. It seems like something  
should either be a hasref or not. I didn't realize perl would be this  
context sensitive, even with strict off.

-- 
Trevor


More information about the Raleigh-talk mailing list