Thanks for that explanation Jason, I'm always happier when I know *why*
something doesn't work.
What I've ended up doing, and was also suggested in another branch of
this thread was to pass a reference to the whole array, and a start and
end index number. This appears to provide the fastest running code.
Gary
On Thursday 17 May 2001 2:04 am, King, Jason wrote:
> Gary wrote ..
>
> >>>> &file_control(\@lines[10..36]); # pass pointer to array elements
>
> I just wanted to add something for those that are interested in what
> the above actually does .. let's use an example
>
> @foo = qw/a b c d e f g h i j/;
>
> then we do this
>
> $bar = \@foo[3..6];
>
> what it does is creates an array slice (which is just a list) and
> then evaluates that list in scalar context (the 'taking the
> reference' is the lowest precedence) .. so the above is the same as
>
> $bar = \qw/d e f g/;
>
> a list in scalar context evaluates to the last element of that list
> .. so the above becomes
>
> $bar = \8;
>
> in other words .. $bar will end up with a reference to the last
> element of the slice .. so the original code is the same as
>
> $bar = \$foo[6];
>
>
> it should be noted .. that even if there was some magical way of
> getting the reference to the array slice .. because Perl only has
> references and not pointers .. the array slice would still be copied
> (behind the scenes) to a new memory location
>
> with that caveat in place .. just for the curious onlookers .. this
> does what Gary thought he wanted
>
> $bar = [ @foo[3..6] ]; # THIS MAKES A COPY OF THE ELEMENTS !!!
>
> but I repeat that the above makes a new copy of the elements on the
> array slice and THEN grabs a reference to that new memory .. the only
> array reference that can be grabbed without making a copy is a
> reference to the start of the @foo array
--
Gary Stainburn
This email does not contain private or confidential material as it
may be snooped on by interested government parties for unknown
and undisclosed purposes - Regulation of Investigatory Powers Act, 2000