Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
So if I read this correctly, you're comparing each element in the array to every other element of the array (but not to itself). So the two foreach loops make sense (mostly). The if statement you used would probably be clearer like this (IMHO):

next if ($element eq $compare);

...but that's just me. For the rest of your question, I think you're going to have to be clearer on what pairs of data match. I can tell you now that it's probably going to involve something along these lines:

($front, $back) = split /:/, $compare; if ( $compare =~ /:$back$/ ) { # do something }

Also, if you use for loops instead of foreach loops, you could make sure that the inner loop always starts at the same index as the outer loop (plus one), which should cut your runtime roughly in half. (Unless the a<=>b comparison is not the same as the b<=>a comparison, in which case, keep the foreach loops.)

More info, please?

--J

Update: Okay, I read the code some more, and it looks like the first part has a number, and when you compare, you're looking for a multiple of that number (including zero). That's simple modulo arithmetic. You can do this to catch the first part:

$moduloc = () = $compare =~ /X(\d+):/; # Grab the divisor. $moduloe = () = $element =~ /X(\d+):/; # Grab the other one. next if ( not $modulo ); # otherwise zero always matches. if ( not ($moduloe)%($moduloc) ) { # Do something. }

We say, 'if not (math)' because if the first part modulo the second part comes out even, the return will be zero. Hence 'not' to make the test true.

Could still use some more information on what should and shouldn't match, though. I'm just guessing, here.


In reply to Re: recursive array search by Rhys
in thread recursive array search by state-o-dis-array

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 scrutinizing the Monastery: (4)
As of 2024-04-16 15:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found