in reply to Re: Can you take a slice of an array reference?
in thread Can you take a slice of an array reference?

Why not simply:
print @$r[0..2];

Replies are listed 'Best First'.
Re: Can you take a slice of an array reference?
by clintp (Curate) on May 24, 2001 at 17:14 UTC
    Because when I'm explaining in class, or in a book, I usually leave the braces around the expression for clarity. Given:
    $a=\@foo;
    that $a is now a reference to an array and, syntatically, it can be used as a stand-in for an array name. Now knowing this, treat @{$a} as you would @foo and get the same results:
    @{$a}; # Same as @foo ${$a}[1]; # Same as $foo[1] @{$a}[0..2]; # Same as @foo[0..2]
    It's just a teaching tool, and I've used it before with great success. And when they're confortable with this you can remove the braces (reminding them of precedence) and when they've got that down pat, show them -> where they get a dereference for free.