in reply to best data structure
I'm not sure if it's exactly what you were looking for, but I used the built-in perl function grep to examine my list for entries that are already in there. Here's the snippet of code I used to test the grep function:
This results in the output: 9,2,3,4,5,6,7,8.
Hope this helps -- Rolly
Update: See comments below for reasons why this isn't an efficient solution.
# Create an initial list @list = (9,2,3,4,5,6); # Data we wish to insert @insert_data = 4..9; # For every datum that we wish to # insert, check for it's existance # in the list and append it if it is # not found foreach $item (@insert_data){ next if grep /$item/, @list; push @list, $item; } # Print out our final list foreach $item (@list){ print $item, ","; }
This results in the output: 9,2,3,4,5,6,7,8.
Hope this helps -- Rolly
Update: See comments below for reasons why this isn't an efficient solution.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: best data structure
by fruiture (Curate) on Aug 28, 2002 at 14:29 UTC | |
Re: Re: best data structure
by rob_au (Abbot) on Aug 28, 2002 at 13:58 UTC |
In Section
Seekers of Perl Wisdom