TedYoung has asked for the wisdom of the Perl Monks concerning the following question:

In the perl 5.8 release notes, it states that the syntaxes:
@a->[...] %h->{...}
have now been deprecated. I cannot find any documentation that described what these did, and I am burning to find out. Any ideas?

Thanks
Ted Young
($$<<$$=>$$<=>$$<=$$>>$$) always returns 1. :-)

Replies are listed 'Best First'.
Re: Deprecated Syntax in 5.8
by djantzen (Priest) on Dec 16, 2002 at 20:52 UTC

    Under (at least) 5.6.1 it enables you to say:

    @a = qw/foo bar/; print @a->[1];
    And see 'bar' as a consequence rather than insisting upon:
    print $a[1];
    print @a[1];
    results in: Scalar value @a[1] better written as $a[1].

    Interestingly, in Perl 6 @a[1] will be valid again since the convention that the leading sigil should indicate return value as opposed to the type of thingy you're accessing is confusing. I take it that this arrow syntax was an attempt to bridge the two approaches, but I didn't even know about it til you brought it up :^)

Re: Deprecated Syntax in 5.8
by PodMaster (Abbot) on Dec 16, 2002 at 20:44 UTC
    It's an obscure syntaxt for hash/array access that nobody ever used.

    my @a = 1..10; my %h = 1..10; warn @a->[1]; die %h->{3}; __END__


    MJD says you can't just make shit up and expect the computer to know what you mean, retardo!
    ** The Third rule of perl club is a statement of fact: pod is sexy.

      I find the combination of the subject of this thread and your sig to be fairly amusing.

      In this case it seem that you can indeed make shit up and expect the computer to know what you mean.

      ;-)

      --- demerphq
      my friends call me, usually because I'm late....

Re: Deprecated Syntax in 5.8
by JamesNC (Chaplain) on Dec 16, 2002 at 21:01 UTC
    I had previously posted: @a->.. and %h->{...} are described in perldsc Data Struct Cookbook
    My original posting is wrong, and I have been corrected. (even humbled)... I apologize if I pointed someone in the wrong direction. Since I had no idea what the syntax was I was GUESSING that it might be another way to reference varibles in anonymous structures. previous self-pity stuff removed too
      @a->... and %h->{...} are described in perldsc Data Struct Cookbook.
      No they aren't. They've always been conceptually illegal syntax. The problem is, up to 5.8, their illegality hadn't been enforced by the compiler, and so people who just throw random things together (rather than understanding what they're doing) ended up taking advantage of the lack of syntax checking.

      @a->[$foo] is correctly written $a[$foo], while %h->{$bar} is correctly written as $h{$bar}. No references involved at all.

      -- Randal L. Schwartz, Perl hacker
      Be sure to read my standard disclaimer if this is a reply.

      But your example structures aren't anonymous; if they were they wouldn't have names e.g., a and h! An anonymous structure is declared like:

      my %hash = (); $hash{foo} = [qw/bar/];

      Here foo in %hash points to a reference to an anonymous array containing bar.

      Another common usage is in parameter passing:

      sub some_func { my $args = shift; } some_func( { foo => 'bar' } );

      Here an anonymous hash is created to hold the function arguments, which is then referred to by the scalar $arg inside the subroutine.

      I couldn't find the section you were referring to in perldsc. Can you be more specific?

      Update: clarified second example; the scalar $arg contains a reference to the anonymous hash.