[Raleigh-talk] life without use strict

Mike South msouth at gmail.com
Thu Feb 12 09:24:56 PST 2009


On Thu, Feb 12, 2009 at 7:19 AM, Trevor Little <trevormg19 at gmail.com> wrote:
> 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.

Something to keep in mind with code like this is that if, say, $var
gets incremented, your next deref will be of a completely different
variable:

#!/usr/bin/perl

my $var;
$var = 1;
$var->{key} = '123456789';

print "$var->{key} is what it is now, but \$var->{key} after \$var is
++'d: (giving [". ++$var . "]) is [$var->{key}]\n";

gives "123456789 is what it is now, but $var->{key} after $var is
++'d: (giving [2]) is []"

mike
>
> 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.
>
> _______________________________________________
> Raleigh-talk mailing list
> Raleigh-talk at pm.org
> http://mail.pm.org/mailman/listinfo/raleigh-talk
>


More information about the Raleigh-talk mailing list