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

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."

    A reply falls below the community's threshold of quality. You may see it by logging in.
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 (Bishop) 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