in reply to Re: If condition failing..
in thread If condition failing..

1.What is the use of undef here?

$pathname_versions{$1}{$2} = undef;

2.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?

Replies are listed 'Best First'.
Re^3: If condition failing..
by Anonyrnous Monk (Hermit) on Dec 13, 2010 at 01:08 UTC

    I didn't follow the discussion in the original thread, so maybe I'm missing something... but why don't you store the version as the value of the hash entries?

    while (<IN>) { # first list next unless ( m:(.+?)#(\d+)$: ); $pathname_versions{$1} = $2; }

    In this case you could later simply do (where $pathname_versions{$1} retrieves the corresponding version from the first list)

    while (<IN>) { # second list next unless ( m:(.+?)#(\d+)$: ); ... if ( $pathname_versions{$1} < $2 ) { ...

      Actually I want the other way like below,but if i use it i am getting the below error.

      if ( $pathname_versions{$1} > $2) { #if the version in list2 i +s less than version for the same path in list1 print "IN\n"; }

      Can't use string ("6") as a HASH ref while "strict refs" in use at orphan_overwrite.pl line 30, <IN> line 28

        Can't use string ("6") as a HASH ref

        This is probably because somewhere else you still have $pathname_versions{$1}{$2}.

        So, if $pathname_versions{$1} is now "6", for example, the {$2} would be trying to dereference the value "6", i.e. "6"->{$2}, which doesn't make much sense...