Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Perl and data types (use Config;)

by Nr1culprit (Initiate)
on Jul 17, 2008 at 15:12 UTC ( #698322=perlquestion: print w/ replies, xml ) Need Help??
Nr1culprit has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks,

I have this script that I use when I need to check perl's data type size in whatever machine I sit on (see below).

As you can see, it uses Config to report integers and double.

Does anybody know how to ask about single precision? Hint: it is not singlesize or floatsize.

Thank you,

Nr1culprit

The script:

#!/usr/bin/perl use strict; use warnings; use Config; print 'short ', $Config{shortsize}, "\n"; print 'int ', $Config{intsize}, "\n"; print 'long ', $Config{longsize}, "\n"; print 'longlong ', $Config{longlongsize}, "\n"; print 'doublesize ', $Config{doublesize}, "\n"; print 'byte order ', $Config{byteorder}, "\n"; exit;

Update:I got it to work just fine with pc88mxer suggestion.

Thank you.

Nr1culprit

In case you are interested, my little script now looks like this:

#!/usr/bin/perl use strict; use warnings; use Config; print 'short ', $Config{shortsize}, "\n"; print 'int ', $Config{intsize}, "\n"; print 'long ', $Config{longsize}, "\n"; print 'longlong ', $Config{longlongsize}, "\n"; print 'f via pack ', length(pack("f", 1.1)), "\n"; print 'doublesize ', $Config{doublesize}, "\n"; print 'byte order ', $Config{byteorder}, "\n"; exit;

Previous content restored and update tag added by GrandFather

Comment on Perl and data types (use Config;)
Select or Download Code
Replies are listed 'Best First'.
Re: [OT] Perl and data types (use Config;)
by psini (Deacon) on Jul 17, 2008 at 15:53 UTC

    In general it is not nice to delete the content of a node. Better add a paragraph at the end saying "Update: I've done this and that...".

    SoPW should not be a chat, it is an archive of the collective experience of the monastery.

    Now we have a thread with the answers to a question that is no more here, it is not kind to the future monks that will do a search for a similar problem.

    Rule One: "Do not act incautiously when confronting a little bald wrinkly smiling man."

      psini,

      Deleting the initial question was a mistake, not a deliberate action. This was my first SoPW question.

      Thanks for pointing out to the monks community my imperfections. I hope you feel better now.

        I'm sorry, I didn't mean to be offensive.

        Perhaps the tone of my post was wrong, but I really intended only to help you, not criticize.

        Rule One: "Do not act incautiously when confronting a little bald wrinkly smiling man."

        So, um, what was the original question?

        --
        Wade
Re: Perl and data types (use Config;)
by pc88mxer (Vicar) on Jul 17, 2008 at 15:25 UTC
    How about using pack()?
    print 'singlesize ', length(pack("f", 1.0)), "\n";
Re: Perl and data types (use Config;)
by Fletch (Chancellor) on Jul 17, 2008 at 15:30 UTC

    Perhaps the .*type values might serve for what you're looking for? They give the C data type used:

    $ perl -V:i8type -V:i16type -V:i32type -V:nvtype i8type='char'; i16type='short'; i32type='long'; nvtype='double';

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

Re: Perl and data types (use Config;)
by Narveson (Chaplain) on Jul 17, 2008 at 15:29 UTC
    use Config; $, = "\n"; print sort grep {/size$/} keys %Config;

    On my system I get

    charsize d_chsize doublesize fpossize gidsize i16size i32size i64size i8size intsize ivsize longdblsize longlongsize longsize lseeksize nvsize ptrsize shortsize sig_size sizesize u16size u32size u64size u8size uidsize uvsize

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (7)
As of 2015-07-31 01:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (274 votes), past polls