Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Testing if an array contains a value and then deleting it in most efficient way

by Skeeve (Parson)
on Feb 18, 2008 at 14:40 UTC ( [id://668562]=note: print w/replies, xml ) Need Help??


in reply to Testing if an array contains a value and then deleting it in most efficient way

If you say "contains" the answer is most often "hash". But you should explain a bit more. Maybe some code you've already done. It's a bit difficult to give an answer when you don't supply enough information.

s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
+.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e

Replies are listed 'Best First'.
Re^2: Testing if an array contains a value and then deleting it in most efficient way
by karpatov (Beadle) on Feb 18, 2008 at 15:54 UTC
    OK.
    I have
    1. a list of chemical compound IDs (10.000 IDs)
    2. a xml output of a database with the records for compounds identified by the ID (almost million records) splitted into .xml files by 25.000.

    What I want to get certain value buried in the xml tree for an individual compound when the compound`s ID is in my list.
    During the weekend I was trying to solve a similar problem, when I was parsing other type xml of output, I wanted buried value from records that were containing some value conforming regex. When regex pattern was found the record was parsed by XML:twig (building only the twigs with value of interest and children_text). This strategy (regex and only then xml:pareser), adviced me by Monks pc88mxer and graff, worked great and in fact the IDs I have now are the result. The only difference now is that the records to be xml-parsed should be selected by extracting relevant value for <compoundID>value</compoundID> by regex and then checking if this value is among 10.000 IDs. So I am looking for most efficient way how to look-up the array of IDs (and deleting already found to speed-up the process). Is there some other strategy?
    Tx for reply.

      I think Skeeve is correct. Your best way forward is a hash of the ids.

      my %set_contains = map { $_ => 1 } @id_set; if ( $set_contains{$some_id} ) { # $some_id is in the set } # removes $some_id from the set: delete $set_contains{$some_id};

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (2)
As of 2024-04-26 00:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found