[Raleigh-talk] life without use strict

Trevor Little trevormg19 at gmail.com
Thu Feb 12 05:19:55 PST 2009


Ian,
    You're absolutely right. I knew it was using a symbolic reference, but  
somehow I didn't put all the pieces together. In the code where I found  
this the var was getting passed several methods deep before being  
dereferenced and I think that got me confused. Anyway, that's for setting  
me straight.

Trevor

On Wed, 11 Feb 2009 17:51:05 -0500, Ian Kilgore <iank at cpan.org> wrote:

> On Wed, Feb 11, 2009 at 05:11:39PM -0500, Trevor Little wrote:
>> 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";
>>
>
> [...]
>
>>
>> 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
>
> without strict, it's using "1" as a symbolic ref.  Try this:
>
> $var = "1";
> $var->{foo} = 'bar';
>
> $foo = "1";
> print $foo->{foo};
>
> You ought to get 'bar'.
>
> With strict 'refs', it will refuse to use symbolic references, so it
> won't use "1" as a reference, and you don't get that far.


More information about the Raleigh-talk mailing list