in reply to Comparing files

The first bit (getting the 30 file names) would be easier/better/clearer using a glob (actually your use of qx has a syntax error -- no closing slash or semicolon); and keeping track of MAC values and files that have them is best done with a hash (similar to what davido suggested, but slightly different):
use strict; my @all_files = </export/home/*_01day>; # angle brackets around a bareword path pattern returns all matchi +ng file names my %macs_found; for my $path ( @all_files ) { my $file = $path . ":"; $file =~ s{.*/}{:}; # now it's ":*_01day:" unless ( open( FILE, $path )) { warn "open failed on $path: $!\n"; next; } while (<FILE>) { chomp; $macs_found{$_} .= $file unless $macs_found{$_} =~ /$file/; } close FILE; } # Now for each mac value, see how many files had it: my $nfiles = scalar @all_files; for my $mac ( sort keys %macs_found ) { if ( split( /::/, $macs_found{$mac} ) == $nfiles ) { print "$mac found in all $nfiles input files\n"; } }
(untested)

Replies are listed 'Best First'.
Re^2: Comparing files
by dannyp (Novice) on Jul 20, 2004 at 23:26 UTC
    Your the man, Thanks for your help.
Re^2: Comparing files
by dannyp (Novice) on Jul 21, 2004 at 19:45 UTC
    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);
      (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.)