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??
Your specification isn't very exact. Looks like you want two different functions. I suggest you take advantage of Perl's testing modules to specify what you want with several examples, and then play with code until all your tests pass. You can take advantage of eq_array to compare arrays. (Note: if your arrays contain references, you have more decisions to make.)

For example one of the things you're looking for seems to be to delete duplicates while preserving order. Let's call this first_filter.

use Test::More qw(no_plan); eq_array([first_filter(qw/one two three/)], [qw/one two three/], "clean list doesn't get changed"); eq_array([first_filter(qw/one one one/)], [qw/one/], "simple repetition removed"); eq_array([first_filter(qw/one two one/)], [qw/one two/], "interleaved repetition removed");

...and so on. The nice thing about this is that if I got it wrong, and this isn't the function you want, you can change the test and add more examples to clarify what you mean. When people offer you suggestions for implementation, you can with one line check their stuff and immediately see if it does everything you want it to.


In reply to Re: Comparing arrays in perl. by gaal
in thread Comparing arrays in perl. by anand_perl

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 chilling in the Monastery: (2)
As of 2024-04-26 00:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found