in reply to The syntaxes @a->[...] and %h->{...} have now been deprecated

@a = ( 0, 1, 2, 3, 4 ); print 'could ', @a->[2], $/; print 'use ', $a[2], $/; print 'or(bad)', @a[2], $/;

The 'bad' syntax works but gets a single element 'slice' and is in array (not scalar) context which may behave in slightly unexpected ways for which I can not generate a one line example. Same holds for hashes $h{foo} instead of %h->{foo}

cheers

tachyon

s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Replies are listed 'Best First'.
Re: Re: The syntaxes @a->[...] and %h->{...} have now been deprecated
by sauoq (Abbot) on Jun 11, 2003 at 16:57 UTC
    The 'bad' syntax works but gets a single element 'slice' and is in array (not scalar) context which may behave in slightly unexpected ways for which I can not generate a one line example.

    I don't think this really has anything to do with slices. Nor is it a matter of context. It's just a syntactical freak of Perl nature... Frankenstyle.

    Some examples:

    perl -le '@foo = qw( f o o ); print @foo->[0]' # Frankenstyle perl -le '@foo = qw( f o o ); print @foo->[0,1,2]' # Frankenslice? perl -le '@foo = qw( f o o ); print @foo[0,1,2]' # Working slice. #### And a demo of context... perl -wle 'sub c {print wantarray ? "list" : "scalar" } my @foo; @foo += c;' perl -wle 'sub c {print wantarray ? "list" : "scalar" } my @foo; $foo[ +0] = c;' perl -wle 'sub c {print wantarray ? "list" : "scalar" } my @foo; @foo[ +0,1] = c;' # And Frankenstyle.... perl -wle 'sub c {print wantarray ? "list" : "scalar" } my @foo; @foo- +>[0] = c;'

    -sauoq
    "My two cents aren't worth a dime.";