Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Re: Any improvement over the code possible??

by toolic (Bishop)
on Sep 21, 2012 at 16:50 UTC ( #994944=note: print w/replies, xml ) Need Help??

in reply to Any improvement over the code possible??

Add input checking. If I input "2" and "F", the code tells me the average is 1. That is probably not how you want the code to behave. Look at Scalar::Util::looks_like_number.

See also:

  • Comment on Re: Any improvement over the code possible??

Replies are listed 'Best First'.
Re^2: Any improvement over the code possible??
by Rohit Jain (Sexton) on Sep 21, 2012 at 17:08 UTC

    Thanks for reply :)

    I tried out this code.. but its not giving what I expected. Is it how it works??

    #!/perl/bin use v5.14; use Scalar::Util; say &Scalar::Util::looks_like_number('2');

    I haven't studied till packages and modules.. So, don't know exactly how to use them..

      its not giving what I expected
      You need to tell us what you expect it to do. Or read the doc I linked to:
      looks_like_number EXPR Returns true if perl thinks EXPR is a number.

      Super Search is another way to find answers and see code examples.

        If I write like this: -

        say looks_like_number '2'

        It should return false as I understand.. but its not printing anything

        Neither in the case I give there a number 2

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://994944]
[Discipulus]: which of 43 significance of NN?
[Discipulus]: NN?
[beech]: nobliest nodes
[Discipulus]: ah no newest nodes! ask something
[beech]: why is my butt itchy
Discipulus many countries without bidet.. is a big problem!
[beech]: who told you i call my butt france?

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2016-12-09 09:44 GMT
Find Nodes?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:

    Results (150 votes). Check out past polls.