Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

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

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


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.


Thank you.

Re: slices

okey wrote:
Quoted text here. Click to load it

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

Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction.                   -- Albert Einstein

Re: slices

Quoted text here. Click to load it

I like to apply "Use Rule 1" from perlreftut in 3 steps:

    mysubsub( @array[ 1 .. 2 ] )  # pretend it is a plain array (slice)

    mysubsub( @{   }[ 1 .. 2 ] )  # replace array name with a block

    mysubsub( @{ $pF }[ 1 .. 2 ] )  # fillin block with the right kind of ref

Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg0cm.j.dat/"
The above message is a Usenet post.
I don't recall having given anyone permission to use it on a Web site.

Re: slices

Quoted text here. Click to load it
That should be

mysubsub( @[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.


"We will need a longer wall when the revolution comes."
    --- AJS, quoting an uncertain source.

Site Timeline