Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Distiguishing arguments: number-strings vs real integer

by tobyink (Canon)
on Aug 10, 2018 at 15:07 UTC ( #1220201=note: print w/replies, xml ) Need Help??


in reply to Distiguishing arguments: number-strings vs real integer

I want to find out if a function is called with an integer or a string containing an integer.

The best solution is to stop wanting that.

Generally speaking, a function which expects a number shouldn't care whether the number was supplied as a string or not, and a function which expects a string shouldn't care if you neglected to wrap a numeric-looking string in the proper quote marks.

If your function can be given either a number or a string and is supposed to do different things with each, consider rewriting it into two different functions, so the caller can choose which behaviour they want.

  • Comment on Re: Distiguishing arguments: number-strings vs real integer

Replies are listed 'Best First'.
Re^2: Distiguishing arguments: number-strings vs real integer
by LanX (Archbishop) on Aug 10, 2018 at 15:23 UTC
    I somehow agree with you, but I didn't design SQL and have the general desire to warn my user about such glitches.

    And if this dogma was generally true, this would mean that Data::Dumper was mis-designed.

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

      SQL is typed, each column has a type, each function's return value has a type.

      Data::Dumper tries to do the impossible. I've just finished the first part of my slides for Glasgow, they show the problems with various JSON modules, how their results are different in corner cases, how their versions differ in what they return, and how the same version could return different results under different Perl versions. You've chosen a long, dark, and distressful path.

      ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
        > You've chosen a long, dark, and distressful path.

        Probably, but if it comes to variables, I will delegate the decision to DBI about how to handle the placeholder by providing the original value.

        And if it comes to literals I hope Data::Dumper "does the possible".

        Cheers Rolf
        (addicted to the Perl Programming Language :)
        Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (6)
As of 2020-04-04 00:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The most amusing oxymoron is:
















    Results (32 votes). Check out past polls.

    Notices?