Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Unique entries from an array

by Not_a_Number (Parson)
on Nov 07, 2009 at 20:07 UTC ( #805678=note: print w/ replies, xml ) Need Help??


in reply to Unique entries from an array

there may be several duplications...

Not enough information. Do you mean:

1 Duplicated names in the array? (eg dad_and_brittney.jpg occurs more than once?). In that case, pre-process your array to exclude such duplicates:

# Assume @all_pics to be your array my %seen; @all_pics = grep !$seen{$_}++, @all_pics;

2 You don't want to display a picture that has already been shown?

my $pic = splice @all_pics, rand @all_pics, 1;

3 You have duplicate pictures with different names? That's a whole 'nother problem...


Comment on Re: Unique entries from an array
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://805678]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (10)
As of 2015-07-05 19:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (67 votes), past polls