in reply to Re^2: Comparing the filepaths and versions in two hashes
in thread Comparing the filepaths and versions in two hashes

1.What's wrong with the below code.I am getting the below error

syntax error at orphan_overwrite.pl line 25, near "}{" syntax error at orphan_overwrite.pl line 35, near "}" Execution of orphan_overwrite.pl aborted due to compilation errors.

2.Is the if condition"if ($2 < pathname_versions{$1}{$2} )" valid?Does pathname_versions{$1}{$2} give the version value in List1 ?How do I access the value for the matched path in list1 and compare?

#!/usr/bin/perl use strict; use warnings; use Data::Dumper; @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; } print Dumper( \%pathname_versions ); open( IN, $list2 ) or die "$list2: $!"; while (<IN>) { next unless ( m:(.+?)#(\d+)$: ); #print "\nLIST 2:$1 $2"; if ( exists( $pathname_versions{$1} )) { if ($2 < pathname_versions{$1}{$2} ) {#if the version in list2 + is less than version for the same path in list1 print "$1 pathname_versions{$1}{2}->$2"; } 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^4: Comparing the filepaths and versions in two hashes
by Anonyrnous Monk (Hermit) on Dec 13, 2010 at 00:00 UTC

    Details matter.  In

    pathname_versions{$1}{$2}

    you omitted the '$' sigil.