in reply to remove a random variable from an array

do this
for($i=1; $i<=$a; $i++){ $randomelement = int(rand @thumbs); print "<img src=\"$picture_directory/$thumbs[$randomelement]\"> +$picture_directory/$thumbs[$randomelement]<br>"; splice(@thumbs, $randomelement,1); }
you need the int() since rand returns a decimal, and you were trying to splice out the value of the array index, not the actual index number...
                - Ant

Replies are listed 'Best First'.
(bbfu) (integer array indices) Re(2): remove a random variable from an array
by bbfu (Curate) on Apr 20, 2001 at 02:02 UTC

    @arr = qw(zero one two three four five); print "$_: $arr[$_]\n" for(3, 3.1415926);

    Prints:

    3: three 3.1415926: three

    No worries. Just thought you might like to know. :-)

    bbfu
    Seasons don't fear The Reaper.
    Nor do the wind, the sun, and the rain.
    We can be like they are.

      Huh... no real surprise perl is smarter than a decimal number :)
                      - Ant