Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: comparing contents of two arrays and output differences

by RichardK (Parson)
on Jan 02, 2015 at 11:27 UTC ( [id://1111988]=note: print w/replies, xml ) Need Help??


in reply to comparing contents of two arrays and output differences

Why not just check if the backup exists for each input file using one of the filetest operators -X ?

for my $file (glob('*.xml') ) { if (-r "$file.bak" ) { print "backup found for $file\n"; } }

Replies are listed 'Best First'.
Re^2: comparing contents of two arrays and output differences
by PitifulProgrammer (Acolyte) on Jan 02, 2015 at 12:14 UTC

    Dear RichardK

    Thanks a mil for your reply. To be honest I have not yet considered the possibility of checking if there was a backup of the files ( since I trust the script :) ). I will surely implement your suggestion. It complements the code nicely, espcially if one considers that I won't be the one using the script

    I am however more interested in what was changed in each of the files ( if changes were made ), hence the reference to diff utilities.

    I am sorry if the description of my problem might have been a misleading or not that well written

    Thanks a mil again for your input

    Kind regards

    C.

      The code you posted only compares the filenames not the content of the files, hence my confusion.

      why not shell out to `diff` if that's giving you the results you need? or try something from cpan like Text::Diff ?

        Dear RichardK

        Thanks a mil for pointing that out. I guess I was confused when tackling the problem. Explains why I could not figure it out

        I will check out that module ( I might have already done so, but I'll give a second go ). Just out of curiosity: The approach would then be to open each file in the one array, open the corresponding backup file in the second array and then compare the contents. After that close both files and do the same thing with the next file until all files have been compared?

        I am indeed using the shell, but I guess future users will not be familiar with the shell, that's why I was looking for a more or less "built-in" solution

        I'll post my results once I had a chance of getting back to the code

        Thanks again for providing a new perspective.

        Kind regards

        C.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (6)
As of 2024-04-19 12:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found