Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^3: Getting error when trying to compare two files

by Happy-the-monk (Abbot)
on Nov 13, 2015 at 09:40 UTC ( #1147648=note: print w/replies, xml ) Need Help??


in reply to Re^2: Getting error when trying to compare two files
in thread Getting error when trying to compare two files

What is the goal you are trying to achieve?

If you want to know the differences between the files, Algorithm::Diff is better suited than File::Compare.

Cheers, Sören

Créateur des bugs mobiles - let loose once, run everywhere.
(hooked on the Perl Programming language)

  • Comment on Re^3: Getting error when trying to compare two files

Replies are listed 'Best First'.
Re^4: Getting error when trying to compare two files
by adalamre (Initiate) on Nov 16, 2015 at 07:18 UTC

    Hi, I want to compare all the content and report all differences. Also I am facing some challenge in comparing like when I have captured the content from Linux, it may not match against output from Windows (and vice-versa) since the line ending pattern of Windows would contain a \r\n (Thatís a carriage return followed by linefeed) instead of a plain \n in the case of Linux. Please let me know how I can handle these Also can you please let me know how to use Algorithm::Diff

      I want to compare all the content and report all differences.

      If you feel better at home with external commands, diff is the one you should be looking at.

      Also I am facing some challenge in comparing like when I have captured the content from Linux, it may not match against output from Windows (and vice-versa) since the line ending pattern of Windows would contain a \r\n (Thatís a carriage return followed by linefeed) instead of a plain \n in the case of Linux. Please let me know how I can handle these

      There are a few options for that. Again if you prefer external commands, look for dos2unix or unix2dos. In Perl, you can substitute with s/\015\012/\012/ - depending on your beforehand knowledge of the size of the files, if they are small, you can treat the whole file in one go or use a while loop to save memory and sacrifice time instead.

      can you please let me know how to use Algorithm::Diff

      Have you tried using some example from the Algorithm::Diff documentation? Did it produce an unforeseen result?

      Again, the question of size may hit you here again. Just for the first go, I'll hope it doesn't ;-)

      Cheers, Sören

      Créateur des bugs mobiles - let loose once, run everywhere.
      (hooked on the Perl Programming language)

Re^4: Getting error when trying to compare two files
by adalamre (Initiate) on Nov 13, 2015 at 10:01 UTC

    I have my expected output in one file which is of some 10 lines and when I execute perl program it will generate output which I am copying to a different file.

    Now I need to compare actual vs expected? How I can achieve this?

      As with Laurent_R's question you haven't answered my question either.

      Tell us what your "compare actual vs expected" should be done, what you expect that to answer back, and we can probably show you the way.

      Cheers, Sören

      Créateur des bugs mobiles - let loose once, run everywhere.
      (hooked on the Perl Programming language)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2017-11-19 21:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:













    Results (282 votes). Check out past polls.

    Notices?