On 11-12-18 09:05 PM, John W. Krahn wrote:
David Christensen wrote:
beginners@perl.org:

Hello,

I'm working on some classes with attributes that are array and hash
references, and am confused by what happens when I attempt to slice an
array or hash reference. For example:

7. "$ra->[0, 1, 2]" evaluates to $ra->[2].

$ra is a scalar that holds a reference to an array. $ra->[0]
dereferences an array element. To dereference an array slice use:

@{ $ra }[ 0, 1, 2 ]


8. "$ra->[0 .. 2]" produces two "Use of uninitialized value in range (or
flip)" warnings and evaluates to $ra->[1].

Same here:

@{ $ra }[ 0 .. 2 ]

TIMTOWTDI:

my $ra = [qw( a b c d e f g h )];

my @slice = @$ra[ 1, 2, 3 ];
print "@slice\n";

@slice = @$ra[ 1 .. 3 ];
print "@slice\n";



--
Just my 0.00000002 million dollars worth,
  Shawn

Programming is as much about organization and communication
as it is about coding.

Never give up your dreams.  Give up your goals, plans,
strategy, tactics, and anything that's not working but never
give up your dreams.

http://www.youtube.com/watch?v=cM5A1K6TxxM
"Never, never, never give up."
  Winston Churchill

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to