Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Comparing unordered but similar data files

by Kanji (Parson)
on Sep 23, 2010 at 00:37 UTC ( #861413=note: print w/ replies, xml ) Need Help??


in reply to Comparing unordered but similar data files

Your use of eq is actually comparing the number of elements in each array, which is why you only see a failure if one file has more lines than the other.

If you're using Perl 5.10 or newer, you can achieve what you want using ~~ (the smart match operator) instead:-

if (@sorted ~~ @sorted2) {

If you're using Perl 5.8 or older, you'll need to compare the arrays element by element, an example of which you can find in perlfaq4 - How do I test whether two arrays or hashes are equal?.

    --k.



Comment on Re: Comparing unordered but similar data files
Download Code
Re^2: Comparing unordered but similar data files
by gwam (Initiate) on Sep 23, 2010 at 07:05 UTC
    Thanks alot Kanji! That done the trick. I figured it was something like that. I thought i was going to need a foreach loop to access and compare each element in the arrays. awesome that Perl has that smart match operator. Thanks again you saved me alot of time.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (14)
As of 2014-07-10 22:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (217 votes), past polls