Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
I'm totally guessing, because I don't have sample data, but I think you want to do something like this:
Open both files Read each line from the first file Split it into mount point, total space, used space, free space Do the same for the second file Compare matching mount points to see the differences.
So here's a skeleton program. Notice that the difference between your program and mine is that I'm recording the data in a pair of hashes so I can cross-check them later. I also switched the open() to use the three-arg form to make it clear you mean to read these files. The code to read them is identical, so I pushed it down into a subroutine that creates the hash from the file and then gives it back to the caller.
open( my $firstfile, '<', "DFLOG1.txt"); open( my $secondfile, '<', "DFLOG2.txt"); my %first_machine = consume($firstfile); my %second_machine = consume($secondfile); foreach my $mount_point (keys %first_machine) { if ( exists $second_machine{$mount_point} ) { # Perform calculations here. # $first_machine{$mount_point}->[0] is the total # $first_machine{$mount_point}->[1] is the used # $first_machine{$mount_point}->[2] is the free # Similar for $second_machine. # Print here after doing calculation. } else { print "No mount point corresponding to $mount_point on the sec +ond machine.\n"; } } sub consume { my ($filehandle) = @_; my %result; while ( defined($_ = <$filehandle>) ) { chomp; next unless /dev/; ($mount_point, $total_space, $used_space, $free_space) = split +; $result{$mount_point} = [$total_space, $used_space, $free_spa +ce]; } return %result; }

In reply to Re: Reading in two text files by pemungkah
in thread Reading in two text files by Spartan4ever

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others studying the Monastery: (2)
    As of 2014-11-29 08:51 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My preferred Perl binaries come from:














      Results (204 votes), past polls