http://www.perlmonks.org?node_id=1054237


in reply to Re: I need to know if 32-bit or 64-bit perl is running my script.
in thread I need to know if 32-bit or 64-bit perl is running my script.

Why use external commands when everything and more is already available?

$ perl -V:ptrsize ptrsize='8'; $ perl -MConfig -wE'say $Config{ptrsize}' 8 $ perl -MData::Peek -MConfig::Perl::V -we'DDumper (Config::Perl::V::my +config ()->{config})'
{ alignbytes => 8, api_subversion => 0, api_version => 14, api_versionstring => '5.14.0', archlibexp => '/pro/lib/perl5/5.14.2/aix-64all', archname => 'aix-64all', bincompat5005 => undef, byteorder => 87654321, cc => 'xlc -q64', cccdlflags => ' ', ccdlflags => ' -bE:/pro/lib/perl5/5.14.2/aix-64all/CORE/pe +rl.exp', ccflags => '-q64 -DDEBUGGING -qlanglvl=extended -D_ALL_SO +URCE -D_ANSI_C_SOURCE -D_POSIX_SOURCE -qmaxmem=-1 -qnoansialias -DUSE +_NATIVE_DLOPEN -qlanglvl=extended -I/pro/local/include -q64 -DUSE_64_ +BIT_ALL -q64', ccversion => '11.1.0.8', config_args => '-Dusedevel -Duse64bitall -Uversiononly -Dinc_ +version_list=none -des', cppflags => '-DDEBUGGING -D_ALL_SOURCE -D_ANSI_C_SOURCE -D +_POSIX_SOURCE -DUSE_NATIVE_DLOPEN -I/pro/local/include', d_dlsymun => undef, d_longdbl => 'define', d_longlong => 'define', d_readlink => 'define', d_sfio => undef, d_sigaction => 'define', d_symlink => 'define', dlext => 'so', dlsrc => 'dl_aix.xs', dont_use_nlink => undef, doublesize => 8, exe_ext => '', gccosandvers => '', gccversion => '', git_branch => '', git_commit_id => '', git_commit_id_title => '', git_describe => '', git_snapshot_date => undef, git_uncommitted_changes => '', gnulibc_version => '', hint => 'recommended', inc_version_list => ' ', intsize => 4, ivsize => 8, ivtype => 'long', ld => 'ld', lddlflags => '-b64 -bhalt:4 -G -bI:$(PERL_INC)/perl.exp -b +E:$(BASEEXT).exp -bnoentry -lc -lm -L/usr/local/ppc64/lib64 -L/pro/lo +cal/lib', ldflags => '-L/usr/local/ppc64/lib64 -b64 -q64 -L/pro/loc +al/lib -brtl -bdynamic -b64', ldlibpthname => 'LIBPATH', libc => '/lib/libc.a', libperl => 'libperl.a', libpth => '/usr/local/ppc64/lib64 /lib /usr/lib /usr/ccs +/lib /usr/local/lib /usr/lib64', libs => '-lbind -lnsl -ldbm -ldb -ldl -lld -lm -lcrypt + -lc', longdblsize => 8, longlongsize => 8, longsize => 8, lseeksize => 8, lseektype => 'off_t', myuname => 'aix i3 3 5 0004898ad300 ', nvsize => 8, nvtype => 'double', optimize => '-O', osname => 'aix', osvers => '5.3.0.0', package => 'perl5', patchlevel => 14, path_sep => ':', perl_patchlevel => '', perllibs => '-lbind -lnsl -ldl -lld -lm -lcrypt -lc', privlibexp => '/pro/lib/perl5/5.14.2', prototype => 'define', ptrsize => 8, revision => 5, scriptdir => '/pro/bin', sitearchexp => '/pro/lib/perl5/site_perl/5.14.2/aix-64all', sitelibexp => '/pro/lib/perl5/site_perl/5.14.2', so => 'a', subversion => 2, use64bitall => 'define', use64bitint => 'define', useithreads => undef, uselargefiles => 'define', uselongdouble => undef, usemultiplicity => undef, usemymalloc => 'n', useperlio => 'define', useposix => 'true', useshrplib => 'false', usesocks => undef, usevendorprefix => undef, version => '5.14.2', version_patchlevel_string => 'version 14 subversion 2' }

Enjoy, Have FUN! H.Merijn

Replies are listed 'Best First'.
Re^3: I need to know if 32-bit or 64-bit perl is running my script.
by flexvault (Monsignor) on Sep 18, 2013 at 13:44 UTC

    Tux,

    Very Nice!

    but... something to keep in mind:

    • You may not be able in install CPAN modules in a production system.

    I tested the performance on a test system:

    # *Your method* after installing 2 CPAN modules real 0m0.84s user 0m0.76s sys 0m0.008s # *My method* calling Perl from the command line real 0m0.028s user 0m0.032s # Note: I did this 3 times and 'user' > 'real' +was every time??? sys 0m0.004s

    Granted your routines providing a lot of information, but doing a 'system' call to get some specific information may not be that bad of a hit.

    I'm still going to add this to my bag of tricks. Good job!

    Regards...Ed

    "Well done is better than well said." - Benjamin Franklin

      The first two are CORE capabilities since perl5.003_07. Sorry to sound harsh, but whining that you cannot install from CPAN is bullshit, that is repeated over and over and over again with all possible workarounds here on PM.

      Nagging about startup time might be true for Config::Perl::V, which does quite a bit more than we'd love to just to be able to get the info (not true anymore on perl-5.18, where that info is available directly from CORE, as is Config::Perl::V). The extra time you see is the dumper time, which was just used to show you the content. Try again with just accessing the data required and you will see a considerable speedup. IMHO all those speeds are just noise in the complete picture, but I do not want to compare apples and pears.

      Nagging about Config is just trying to find sand to throw into the engine. You have no idea how many modules use Config, so it will be loaded anyway sooner or later.

      $ find 5.18.0 -name \*.pm | xargs grep -wl 'use Config' | wc -l 57 $ find site_perl/5.18.0 -name \*.pm | xargs grep -wl 'use Config' | wc + -l 107 $ corelist Config Config::Perl::V Data for 2013-08-20 Config was first released with perl 5.00307 Data for 2013-08-20 Config::Perl::V was first released with perl v5.17.9 $ time perl -V:ptrsize ptrsize='4'; 0.005u 0.003s 0:00.00 0.0% 0+0k 0+0io 0pf+0w $ time perl -MConfig -wE'say $Config{ptrsize}' 4 0.001u 0.005s 0:00.00 0.0% 0+0k 0+0io 0pf+0w $ time perl -MConfig::Perl::V -wE'say Config::Perl::V::myconfig ()->{c +onfig}{ptrsize}' 4 0.007u 0.002s 0:00.00 0.0% 0+0k 0+0io 0pf+0w

      Enjoy, Have FUN! H.Merijn

        Tux,

          The first two are CORE capabilities since perl5.003_07. Sorry to sound harsh, but whining that you cannot install from CPAN is bullshit, that is repeated over and over and over again with all possible workarounds here on PM.

        What an arrogant response!

        I guess you've been passed over for management a few times and it shows. So let us take you're two statements, both false. First, those non-core capabilities had to be downloaded from CPAN. I used a Perl 5.14.2 on a test server, so I went to a production machine and:

        > /usr/opt/perl5.12.2/bin/perl -v This is perl 5, version 12, subversion 2 (v5.12.2) built for aix Copyright 1987-2010, Larry Wall . . . > /usr/opt/perl5.12.2/bin/perl -MData::Peek -MConfig::Perl::V -we 'DDu +mper (Config::Perl::V::myconfig()->{config})' Can't locate Data/Peek.pm in @INC (@INC contains: /usr/opt/perl5.12.2/ +lib/site_perl/5.12.2/aix /usr/opt/perl5.12.2/lib/site_perl/5.12.2 /us +r/opt/perl5.12.2/lib/5.12.2/aix /usr/opt/perl5.12.2/lib/5.12.2 .). BEGIN failed--compilation aborted. >

        And the second part that you obviously didn't understand, is that it's not a technical problem, but a management rule. The easiest way to get fired at my company is to load anything on a production server without going through a code review.

        Thank you...Ed

        "Well done is better than well said." - Benjamin Franklin