I'm not sure what you really want in terms of output. What sort of question(s) are you trying to answer regarding the two input lists?

What should happen if a single "path/filename" appears multiple times with different version numbers in the first list, and then in the second list: (a) it never occurs, or (b) it occurs but only with different version numbers, or (c) it occurs with some or all version numbers matching the first list?

In order to compare the two lists on the basis of matches in the full path/name string, it would be easiest to use the path/name string as a primary hash key (and probably use the version numbers as secondary hash keys -- i.e. an HoH structure, rather than HoAoH),

This is different enough from your previous question (Constructing a hash with filepath,filename and filerev) that you probably don't want to start from an exact copy of that code to do this task. Here's how I would start out, but I wouldn't know how to finish it until you clarify what you really want.

#!/usr/bin/perl use strict; use warnings; @ARGV == 2 and -f $ARGV[0] or die "Usage: $0 list1 list2\n"; my ( $list1, $list2 ) = @ARGV; my %pathname_versions; open( IN, $list1 ) or die "$list1: $!"; while (<IN>) { next unless ( m:(.+?)#(\d+)$: ); $pathname_versions{$1}{$2} = undef; } open( IN, $list2 ) or die "$list2: $!"; while (<IN>) { next unless ( m:(.+?)#(\d+)$: ); if ( exists( $pathname_versions{$1} )) { # we have a match on the path/name... now what? if ( exists( $pathname_versions{$1}{$2} )) { # we have a match on version# as well, so... } else { # version number wasn't seen in list1, so... } } }
BTW, you really should learn to use @ARGV and command-line args -- it simplifies a lot of things when you actually use the script, as well as when you write it.

In reply to Re: Comparing the filepaths and versions in two hashes by graff
in thread Comparing the filepaths and versions in two hashes by perl_mystery

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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.