Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re^3: Best method to eliminate substrings from array

by Paladin (Vicar)
on Jun 28, 2019 at 21:39 UTC ( [id://11102099]=note: print w/replies, xml ) Need Help??

in reply to Re^2: Best method to eliminate substrings from array
in thread Best method to eliminate substrings from array

Here OP says that the list of part numbers are to be treated as sets/subsets, so while the original code matches sub-strings, OP says later that is incorrect. My code treats the long strings as ordered sets, which seems to be what the OP wanted. If the OP really wants to treat the list of parts as a non-ordered set, it's easy enough to add a sort to the join line.

OP also says here they are sorting the original list anyways, so the input order seems to be irrelevant.

I'm not quite sure what you mean by the duplicated items part. Essentially what my code does is break each line (set), into individual part numbers (elements), then checks if for each prefix of elements, does that one already exist in the final result, and if it does, remove it from the final result, as this current line will supersede it. So if the current line was "A|B|A|B|C", it first checks if "A" is in the result; If so, remove it. Then checks "A|B", then "A|B|A", etc. until finally adding the entire line "A|B|A|B|C" to the final result. If later in the file, the line "A|B|A|B|C|N" is found, at that point, the "A|B|A|B|C" would get removed.

Log In?

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (2)
As of 2024-04-20 12:29 GMT
Find Nodes?
    Voting Booth?

    No recent polls found