Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Getting error when trying to compare two files

by Happy-the-monk (Canon)
on Nov 13, 2015 at 07:57 UTC ( [id://1147639]=note: print w/replies, xml ) Need Help??


in reply to Getting error when trying to compare two files

DATA is still selected for your print commands, but no longer open. To fix it, insert

my $old_fh = select(STDOUT);

before your line

select DATA;

Then right before or right after your line saying

close DATA;

insert

select($old_fh);

That should make the error go away.


(edit:) Alternatively do not use select but print explicitly to the filehandle instead:

replace this bit of your code

select DATA; print join("\n", @output);

with this bit

print DATA join("\n", @output);

Cheers, Sören

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

Replies are listed 'Best First'.
Re^2: Getting error when trying to compare two files
by adalamre (Initiate) on Nov 13, 2015 at 08:36 UTC
    Yes, this worked. Thank you
Re^2: Getting error when trying to compare two files
by adalamre (Initiate) on Nov 13, 2015 at 08:44 UTC
    Can you please let me know what needs to be done for comparing the content of the files line by line

      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)

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

      Sure, we can help on that, but first tell us what you really want: do you want to just report that the files are equal or not equal, or do you want to just report where (which line) the first difference is found, or do you want to list all the differences? The first two cases are fairly easy, the last one is more complicated and implies some pre-requirements.

        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

        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?

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2024-04-25 18:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found