in reply to Re^2: Nested Hash Dereferencing Syntax
in thread Nested Hash Dereferencing Syntax

Here is an explanation of why parens cannot be used there.

If you could write %($hash{$key}) then you should expect to be able to write %($hash{$key}){$other_key}. But perlvar tells us that $( is a built-in special variable, so correctly knowing how to parse that would be very, very hard.

Incidentally %( is a valid Perl hash, though it is not used for anything and accessing it can get tricky. But the following is valid Perl:

%( = 0..9; print keys(%();

Replies are listed 'Best First'.
Re^4: Nested Hash Dereferencing Syntax
by ikegami (Patriarch) on Feb 24, 2009 at 18:31 UTC
    I thought of that, but dismissed it. He could have named $( something different if he wanted to use parens for variables, or did "${var}" come later? I figured it had been in Perl from the start due to its parallel in bourne.
      I agree that ${...} is certainly originally in Perl because of the familiarity of the syntax in shell. But Perl is willing to change syntax if a new one is clearer - witness the switch from ' to :: as a package separator.

      But my understanding is that references and most of our dereferencing syntax was added in Perl 5. Which means that backwards compatibility would prevent the $(...) syntax from being introduced after that.