Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

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]
[erix]: ok, but mainainability comes after it has been made to work :)
[erix]: maybe I should have cobbled together a more simple example
[erix]: the main question is whether repeating groups get captured. I thought they did but it looks they do not.
[erix]: or they probably get overwritten when the repeating is done

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2018-01-19 08:39 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (216 votes). Check out past polls.