Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re^2: counting elements using a hash

by AnomalousMonk (Canon)
on Sep 23, 2012 at 09:08 UTC ( #995193=note: print w/ replies, xml ) Need Help??

in reply to Re: counting elements using a hash
in thread counting elements using a hash

    next unless $number; #skip undef's

What happens if the extracted  $number string is '0'? Will zeros be counted?

Comment on Re^2: counting elements using a hash
Select or Download Code
Replies are listed 'Best First'.
Re^3: counting elements using a hash
by Marshall (Prior) on Sep 23, 2012 at 12:28 UTC
    That is a good point. These zero's or undef's are problematic.

    The problem statement had 1..100 so this zero didn't enter into the situation. In this case, $number==0 should be skipped (same as undef). So what about $number >100? Well, the OP should should show some revised code and we will iterate again to get it fine tuned. A major point was that Perl will create a new key (auto-vivify) when needed - there is no need to test whether or not the key exists. Second point was a numeric instead of alpha sort.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://995193]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (7)
As of 2015-11-30 08:05 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (765 votes), past polls