INPUT: List1: //depot/asic/tools/perl/scripts/examples/modem.c#7

//depot/asic/tools/perl/files/examples/file.txt#2

//depot/asic/tools/perl/proc/examples/apps.c#14

List2: //depot/asic/tools/perl/scripts/examples/modem.c#6

//depot/asic/tools/perl/files/examples/file.txt#2

//depot/asic/tools/perl/proc/examples/apps.c#12

OUTPUT: Picking File2 overwrites

//depot/asic/tools/perl/scripts/examples/modem.c#7-> 6

//depot/asic/tools/perl/proc/examples/apps.c#14->12

1.What's wrong with the below code.I am getting the below error.Basically I want to print all the lower version filepaths in list2 compared to list1

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... } } }

In reply to If condition failing.. 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.