Perl Gem, Ambiguous Curlies


Deprecated: ord(): Providing a string that is not one byte long is deprecated. Use ord($str[0]) instead in /project/www/bilbo.hobbiton.org/mediawiki-1.23.8/includes/cache/MessageCache.php on line 731

Deprecated: ord(): Providing a string that is not one byte long is deprecated. Use ord($str[0]) instead in /project/www/bilbo.hobbiton.org/mediawiki-1.23.8/includes/cache/MessageCache.php on line 739

Deprecated: Creation of dynamic property PPDStack::$accum is deprecated in /project/www/bilbo.hobbiton.org/mediawiki-1.23.8/includes/parser/Preprocessor_DOM.php on line 754

Deprecated: Constant E_STRICT is deprecated since 8.4, the error level was removed in /project/www/bilbo.hobbiton.org/mediawiki-1.23.8/includes/GlobalFunctions.php on line 2409
From Bilbo

Deprecated: ord(): Providing a string that is not one byte long is deprecated. Use ord($str[0]) instead in /project/www/bilbo.hobbiton.org/mediawiki-1.23.8/includes/cache/MessageCache.php on line 731

Deprecated: ord(): Providing a string that is not one byte long is deprecated. Use ord($str[0]) instead in /project/www/bilbo.hobbiton.org/mediawiki-1.23.8/includes/cache/MessageCache.php on line 739
Jump to:
Deprecated: ord(): Providing a string that is not one byte long is deprecated. Use ord($str[0]) instead in /project/www/bilbo.hobbiton.org/mediawiki-1.23.8/includes/cache/MessageCache.php on line 731

Deprecated: ord(): Providing a string that is not one byte long is deprecated. Use ord($str[0]) instead in /project/www/bilbo.hobbiton.org/mediawiki-1.23.8/includes/cache/MessageCache.php on line 739
navigation

Deprecated: ord(): Providing a string that is not one byte long is deprecated. Use ord($str[0]) instead in /project/www/bilbo.hobbiton.org/mediawiki-1.23.8/includes/cache/MessageCache.php on line 731

Deprecated: ord(): Providing a string that is not one byte long is deprecated. Use ord($str[0]) instead in /project/www/bilbo.hobbiton.org/mediawiki-1.23.8/includes/cache/MessageCache.php on line 739

Deprecated: Constant E_STRICT is deprecated since 8.4, the error level was removed in /project/www/bilbo.hobbiton.org/mediawiki-1.23.8/includes/GlobalFunctions.php on line 2409

Deprecated: Constant E_STRICT is deprecated since 8.4, the error level was removed in /project/www/bilbo.hobbiton.org/mediawiki-1.23.8/includes/GlobalFunctions.php on line 2409
,
Deprecated: ord(): Providing a string that is not one byte long is deprecated. Use ord($str[0]) instead in /project/www/bilbo.hobbiton.org/mediawiki-1.23.8/includes/cache/MessageCache.php on line 731

Deprecated: ord(): Providing a string that is not one byte long is deprecated. Use ord($str[0]) instead in /project/www/bilbo.hobbiton.org/mediawiki-1.23.8/includes/cache/MessageCache.php on line 739
search

2005-08-03

This is quite a perl gem. These statements should do exactly the same thing. Thanks to the multiple meanings of {}, their interpretations are wildly different.

print Dumper(eval '{1 => 2}');
print Dumper(eval '{"1" => 2}');

Generates:

$VAR1 = 1;
$VAR2 = 2;
$VAR1 = {
          1 => 2
        };

2006-09-26 Update: A year later, this doesn't happen anymore. I should've recorded which version of Perl it was. I know I wasn't crazy; I spent a very long time debugging this in a program, and finally extracted these lines to demonstrate to myself that I was not, in fact, crazy. In any case, the point is still valid: It's a terrible idea to overload symbols with too many meanings. Perl uses {} to represent both a statement block and a ref to an anonymous hash, and the grammar does not fully disambiguate them.