in reply to Comparing the filepaths and versions in two hashes
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.
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.#!/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... } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Comparing the filepaths and versions in two hashes
by perl_mystery (Beadle) on Dec 11, 2010 at 21:49 UTC | |
by Anonymous Monk on Dec 11, 2010 at 23:58 UTC | |
by perl_mystery (Beadle) on Dec 12, 2010 at 22:56 UTC | |
by Anonyrnous Monk (Hermit) on Dec 13, 2010 at 00:00 UTC |