Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

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?.


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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://861413]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (2)
As of 2018-05-26 15:37 GMT
Find Nodes?
    Voting Booth?