http://qs1969.pair.com?node_id=31060

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

I have been toying with references for a while now, and I bumped into something interesting. When you pass a reference to an array slice, you are not passing the list reference, but actually the references to each one of the elements in the list (please correct me if this is an incorrect statement).

To prove this, I came up with the following:
# example 1 my @ary = qw( Foo and Bar went up the Baz to fetch a Gom Jabar ); printref(\@ary[0,2,6,10,11]); sub printref { print "$$_\n" for @_; }
And it works... No problem. The I thought of doing it the other way around. First pass the array ref, and then the parameters of what you want from the array. And we have:
# example 2 my @ary = qw( Foo and Bar went up the Baz to fetch a Gom Jabar ); printref(\@ary,(0,2,6,10,11)); sub printref { my $ary = shift; print "$$ary[$_]\n" for @_; }
And again it works! Probably less efficient than the first, but still it works, no problem. Now here for the big trick that I wanted to pull off at first and obviously didn't get it to work:
# example 3 my @ary = qw( Foo and Bar went up the Baz to fetch a Gom Jabar ); printref(\@ary[0,2,6,10,11]); sub printref { my $ary = shift; print "$_\n" for @$ary; }
And we get Not an ARRAY reference at - line 13.. So after all this running around, my question is, "Is there a way to pass a reference of an array slice as a list?" Am I day dreaming again? Am I not understanding a basic concept? Any pointers in the right direction would be very appreciated.

#!/home/bbq/bin/perl
# Trust no1!