develooper Front page | perl.beginners | Postings from September 2009

numeric comparison always returning true!

Thread Next
From:
pablo
Date:
September 24, 2009 11:05
Subject:
numeric comparison always returning true!
Message ID:
20090924180451.GC19427@arch
I have a script that tells me the largest file (in bytes) for each
extension.  I store the largest size in a hash, keyed by the extension.

The numeric comparison portion is clearly not working, since it is returning true every time regardless of the numbers being compared.  Here's a snippet, along with the output shown:

Snippet:
if ( $bytes > $sizes{$ext}->{largest} ) {
    print "$bytes is larger than $sizes{$ext}->{largest_size}\n";
    $sizes{$ext}->{largest_size} = $bytes;
}
else {
    print "$bytes is smaller than $sizes{$ext}->{largest_size}\n";
}
					    
Output:
304785408 is larger than 
407666688 is larger than 304785408
595656704 is larger than 407666688
597778432 is larger than 595656704
568844288 is larger than 597778432
157255680 is larger than 568844288
512342016 is larger than 157255680
616058880 is larger than 512342016
728705024 is larger than 616058880
6008832 is larger than 728705024

Notice that last line?  Am I missing something obvious, or is there
something wrong here?


Pablo

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About