From the OP:
Is the if condition if ($2 < pathname_versions{$1}{$2} ) valid?

No. It should be "$pathname_versions{$1}{$2}" -- note the "$", which is missing from your code. Without that "sigil", perl has to treat "pathname_version" as a function name, but you can't have "{" after (or as part of) a function name.

From one of the sub-replies:

What is the use of undef here? $pathname_versions{$1}{$2} = undef;

That's just an economical assignment statement; by assigning "undef" as the value of a hash element, no memory is allocated to store the value, but the hash key is made to exist.

How do I do a hash look up for the hash pathname_versions to see if $2(version in the second list) is less than the version in the list 1?

Based on your earlier posts, I assume that each input list could have 2 or more entries with the same path/name and different version numbers, so it's still not clear to me what particular task you are trying to accomplish with your code,

You never have said what your real purpose is for the scripts you're trying to write, and I'm getting the impression that you haven't completely worked that out yet. It's hard to write effective code when you aren't sure what it's supposed to do. Anyway, here's a version that shows how to handle cases that involve comparing version numbers, assuming that list1 might contain several versions for a given path:

... open( IN, $list2 ) or die "$list2: $!"; while (<IN>) { next unless ( m:(.+?)#(\d+)$: ); my ( $p, $v ) = ( $1, $2 ); next unless ( exists( $pathname_versions{$p} )); if ( exists( $pathname_versions{$p}{$v} )) { # get here if we have a full match (path and version) } else { # create a sorted list of version numbers from list1: my @list1versions = sort {$a<=>$b} keys %{$pathname_versions{$ +p}}; if ( $v < $list1versions[0] ) { # list2 version number is lower than _all_ matching list1 +entries } elsif ( $v > $list1versions[-1] ) { # list2 version number is higher than _all_ matching list1 + entries } } }
Note how I use indentation to indicate code block nesting for the "if" conditions. Proper indentation is very important for legibility.

In reply to Re: If condition failing.. by graff
in thread 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.