Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
andye,
like this solution, because it's so simple and efficient:

It has at least one bug and I am not sure why you think it is efficient.

First the bug. You have /$uniq[$i]/. This can do the wrong thing for at least two reasons. The first is that it will match "and" in the line of "where is the sand" even though the word "and" never appears. The second reason is that you haven't use \Q\E or quotemeta to ensure any metacharacters are escaped. It doesn't take case into consideration either, but I am not sure any of the solutions do (including my own).

Another potential bug is the fact that you don't consider that in the line "hello world goodbye cruel world" that each pairing of world should double and not be counted once. I am not sure if this is or isn't a requirement but it is a bug in one intepretation.

As to why it isn't efficient. This can be done in a single pass and yet your solution has you going through every line in the data (N^2 - N) / 2 times (where N = # of unique words). In other words, you check every single pairing of unique word against every single line even if the word doesn't appear on that line.

Cheers - L~R


In reply to Re^4: Finding Combinations of Pairs by Limbic~Region
in thread Finding Combinations of Pairs by zod

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2024-04-23 05:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found