Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Comparing unordered but similar data files

by Kanji (Parson)
on Sep 23, 2010 at 00:37 UTC ( [id://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.


Replies are listed 'Best First'.
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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://861413]
help
Chatterbox?
and the web crawler heard nothing...

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

    No recent polls found