At 10:44 AM 5/17/01 +1000, King, Jason wrote:
>so here's the thing .. Perl doesn't have pointers .. only references .. so
>you can't have a 1500 element array and grab a reference to the 700th
>element

Oh yes you can:

my @foo = qw(three blind mice);
my $elemref = \$foo[2];

>  .. because references don't work that way .. pointers work that way
>- but there aint no pointers in Perl

But as you say, you can't make a reference to a slice; you end up with a 
list of references to each element of the slice.  Pity.

Confirming that passing slices to subroutines results in copying:

$ perl -le 'system "ps -lp $$"; @x = 1..1_000_000; system "ps -lp 
$$";foo(@x[1..500_000]); system "ps -lp $$"; sub foo{}'
   F S   UID   PID  PPID  C PRI  NI ADDR    SZ WCHAN  TTY          TIME CMD
000 S   500 30162 30128 96  68   0    - 16513 wait4  pts/0    00:00:04 perl
   F S   UID   PID  PPID  C PRI  NI ADDR    SZ WCHAN  TTY          TIME CMD
000 S   500 30162 30128 54  70   0    - 19482 wait4  pts/0    00:00:08 perl
   F S   UID   PID  PPID  C PRI  NI ADDR    SZ WCHAN  TTY          TIME CMD
000 S   500 30162 30128 51  69   0    - 19971 wait4  pts/0    00:00:08 perl

So your solution of passing a ref to the whole array looks optimal.
--
Peter Scott
Pacific Systems Design Technologies
http://www.perldebugged.com

Reply via email to