in reply to merging arrays

I guess it's not merging that you want so much as slicing You were closeish, but the interpolation was not helping at all. Try this:

use strict; use warnings; my $pics_to_find = 3; my @found_images = (1, 2, 3, 4, 5); my @saved_images = @found_images[0 .. $pics_to_find - 1]; print "@saved_images";

Prints:

1 2 3

DWIM is Perl's answer to Gödel

Replies are listed 'Best First'.
Re^2: merging arrays
by Anonymous Monk on Jun 24, 2006 at 04:49 UTC
    When I went to print that out, it appears as though it indexed every position from the original array into this one. Now it has some 100s of undefined values. I guess it really didn't do as I expected. Maybe I should just do a foreach and do it that way?

      Reduce your code to a small sample that shows the problem and post it.


      DWIM is Perl's answer to Gödel
      That's exactly the expected behaviour. You loop from $a..$n. So you get some value for $a..$n :)
      If you don't want the undefined values, grep for the defined ones:
      my @saved_images = grep { defined $_ } @found_images[0 .. $pics_to_fin +d - 1];
      cheers,
      --shmem
      _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                    /\_¯/(q    /
      ----------------------------  \__(m.====·.(_("always off the crowd"))."·
      ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}