[Raleigh-talk] life without use strict
Ian Kilgore
iank at cpan.org
Wed Feb 11 14:51:05 PST 2009
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.
--
Ian Kilgore
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://mail.pm.org/pipermail/raleigh-talk/attachments/20090211/7a26fa0d/attachment.bin>
More information about the Raleigh-talk
mailing list