in reply to Re: Comparing files
in thread Comparing files

Got one more question for you, I have been trying to replace your print "$mac found in all $nfiles input files to print out to a file instead of the screen. I can't seem to get it, I always get some weird type of output: here is what I did.
open(OUT,">$directory") || die couldn't open file:$directory;
print OUT <$mac;
close (OUT);

Replies are listed 'Best First'.
Re^3: Comparing files
by graff (Chancellor) on Jul 21, 2004 at 22:56 UTC
    (1) When you post, use <code> to mark the beginning of source code, and </code> to mark the end. Always. (In fact, use it when posting data samples, command lines and anything else where spacing or brackets are important.)

    (2) Read the man page description for the "print" function (do "perldoc -f print", or if you're using the docs in html form, browse the "perlfunc" page for the "print" function).

    (3) You seem to think that the angle bracket should be used with "print", as if doing redirection (or maybe you learned C++ first?). Anyway, printing to a file handle works like this:

    print OUT "string to be printed to outputfile\n"; # or like this: $outstring = "string to be printed\n"; print OUT $outstring;
    Really simple. The only thing that's a little strange is that you don't ever put a comma between the file handle and the stuff to be printed to it.

    Update -- one other thing (call it "4") -- just in case you're not clear on this: If you are doing iterations in any sort of loop, and want to print to a file handle on each iteration, be sure to open the file before going into the loop, and close it after the loop. Do NOT open, write and close the file on every iteration. (The format of your question made me worry that this might not be clear.)