Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Looking for a function that returns status of a scalar's numeric flags

by bliako (Monsignor)
on Mar 22, 2020 at 09:49 UTC ( [id://11114541]=note: print w/replies, xml ) Need Help??


in reply to Looking for a function that returns status of a scalar's numeric flags

How about doing it via the guts? Search also perlapi for SvIOKp.

# author: bliako # for: https://perlmonks.org/?node_id=11114538 # 22/03/2020 use Inline 'C'; my $x; $x = "123"; flags($x); $x= 123; flags($x); $x= 123.123; flags($x); __END__ __C__ void flags(SV *sv){ printf("int=%d, double=%d, string=%d\n", SvIOKp(sv)>>12 & 1, SvNOKp(sv)>>13 & 1, SvPOKp(sv)>>14 & 1 ); }

bw, bliako

Replies are listed 'Best First'.
Re^2: Looking for a function that returns status of a scalar's numeric flags
by syphilis (Archbishop) on Mar 23, 2020 at 04:29 UTC
    Search also perlapi for SvIOKp

    Yes, Inline::C has always been my first goto, and I've written plenty of XSubs that reference SvIOK and friends.
    But this is the first time that I've ever been interested in SvIOKp and friends, and I didn't know about them even though they're mentioned in perlapi.
    Thanks for bringing them to my attention.

    I had a little play with them in Inline::C last night, shortly after reading your reply, and an XSub that returned
    SvIOK(sv) | SvNOK(sv) | SvIOKp(sv) | SvNOKp() | SvUOK(sv)
    provided me with all that I needed.
    The only problem being that Inline::C is not core :-(

    Cheers,
    Rob

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2024-04-19 23:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found