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

-- 
  jason king

  It is illegal to "annoy a bird" in any city park of Honolulu, Hawaii.
  - http://dumblaws.com/

Reply via email to