Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Re: Data::Types or grok_number

by tobyink (Abbot)
on Sep 25, 2012 at 16:37 UTC ( #995591=note: print w/replies, xml ) Need Help??

in reply to Data::Types or grok_number

use 5.010; use Scalar::Util qw(looks_like_number); sub is_int (_) { my $i = shift; looks_like_number($i) and int($i)==$i; } say for grep { is_int } qw( -6 5.2 5.0 3e4 0Hello );

Note that this classes 5.0 as an integer, which is correct from a maths point of view, but not necessarily from a comp sci one.

perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

Replies are listed 'Best First'.
Re^2: Data::Types or grok_number
by tqisjim (Beadle) on Sep 25, 2012 at 17:57 UTC

    I was thinking of something along the lines of the following:

    print TQIS::Primitive::typeis("1") ; > string print TQIS::Primitive::typeis(1) ; > integer
    Here is the code:
    #include "EXTERN.h" #include "perl.h" #include "XSUB.h" #include "ppport.h" SV* typeis ( SV* what ) ; SV* typeis ( SV* what ) { if ( SvIOK( what ) ) return newSVpvs( "integer" ) ; else if ( SvNOK( what ) ) return newSVpvs( "double" ) ; else if ( SvPOK( what ) ) return newSVpvs( "string" ) ; return newSVpvs( "unknown" ) ; } MODULE = TQIS::Primitive PACKAGE = TQIS::Primitive PROTOTYPES: ENABLE SV* typeis( what ) SV* what

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://995591]
[Discipulus]: indeed marto I dunno. I tested once and many years ago. But I'm not the programmer yardstick. I try to install Padre via cpan now just to add a line about it in the issue. Strawberryperl all life long!
[marto]: yeah, when I worked on Windows I did use Np++ all the time

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (11)
As of 2018-06-25 08:56 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (126 votes). Check out past polls.