in reply to Can't see the syntax error here...

Perl tries to parse the curly braces as a block, not a hash ref. Use a + to disambiguate: +{$xnix => 100}->{'X'}

Update: BTW this is not related to the sub at all, since a simple print {$xnix => 100}->{'X'}; gives the same error.

Replies are listed 'Best First'.
Re^2: Can't see the syntax error here...
by rovf (Priest) on Jun 16, 2008 at 08:04 UTC

    Amazing!

    I think I would searched for this for years, but once I see your explanation, it becomes clear.

    BTW, the reason why I thought it would be related to sub is that the similar code

    my $f={$xnix => 100}->{'X'};
    works fine, but of course now this is clear too: In the latter case, there is no ambiguity, so it is correctly parsed as a hash. Thanks a lot for helping!

    -- 
    Ronald Fischer <ynnor@mm.st>