slices

O

okey

How do I pass just a "slice to mysubsub()? I have an array reference
to three hashes

$p = [ {a => "1"}, {b => "2"}, {c => "4} ];

mysub($p);


sub mysub {
my ($pF) = @_;
#every thing ok so far

mysubsub($pF); #passes all three

# want something like this, but can't seem to make it work.

mysubsub(@{$pF->[1..2]})

Thank you.
 
J

John W. Krahn

okey said:
How do I pass just a "slice to mysubsub()? I have an array reference
to three hashes

$p = [ {a => "1"}, {b => "2"}, {c => "4} ];

mysub($p);


sub mysub {
my ($pF) = @_;
#every thing ok so far

mysubsub($pF); #passes all three

# want something like this, but can't seem to make it work.

mysubsub(@{$pF->[1..2]})

mysubsub( @{ $pF }[ 1 .. 2 ] )



John
 
M

Mart van de Wege

okey said:
How do I pass just a "slice to mysubsub()? I have an array reference
to three hashes

$p = [ {a => "1"}, {b => "2"}, {c => "4} ];

mysub($p);


sub mysub {
my ($pF) = @_;
#every thing ok so far

mysubsub($pF); #passes all three

# want something like this, but can't seem to make it work.

mysubsub(@{$pF->[1..2]})
That should be

mysubsub( @{$pF}[1..2] }

You first deref the arrayref, then you can slice the resulting
arrray. Of course, you're now passing an array, not a ref, but that if
you need a ref, you can easily fix that.

Mart
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,076
Latest member
OrderKetoBeez

Latest Threads

Top