Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight


by Intrepid (Deacon)
on Aug 06, 2003 at 10:25 UTC ( #281332=sourcecode: print w/replies, xml ) Need Help??
Category: Perl Administration
Author/Contact Info Soren Andersen <somian -AT- pobox *DOT* com> or <somian -AT- cpan *DOT* org>

This simple text-term program shows the breakdown of the Perl configuration belonging to that Perl interpreter being run (ordinarily "perl"). The utility of such a thing will not necessarily be obvious unless the user is an admin who is maintaining one or more Perl installations (more than one is possible per system), or a module author who is trying to write build infrastructure. In the author's experience, it is sometimes desireable to see at a glance the organization of the principle Perl installation directories. Being able to do so may be particularly advantageous when trying to install or upgrade modules and the installation is not going smoothly.

This script was developed on a system running a *nix-type OS (Linux, Debian 3.0r1) and tested against Perl versions 5.6.1 and 5.8.0.

Update:   Thu Aug 7 2003 15:05 UTC
Removed the code relying on File::Find and replaced it with a corrected, simpler subroutine. Perl Monk Aristotle helped direct my attention to that solution in the follow-up below.

Update:   Sun Aug 17 2003 14:03 UTC
Added the *man* dirs to the report. On most or all *nix-like platforms, we install manpages at module installation time, including in cygwin.

Also added a test to make sure a Win32 perl was looked for with .exe suffix. No previous reports from Win32 users had indicated a problem, but some edge case might require this care.

Update:   Sat Jan 10 2004 07:10 UTC
Considerable changes made but they only affect the formatting of the header slightly.

See download from Intrepid's perlmonk site for the most up-to-date release of this script.

Update:   Tue, 13 Feb 2007
The Intrepid site has been partially rebuilt. See the following links offered for readers' convenience:

  • This script's "production copy" with cryptographic signature and all POD in-line: signed

#! /usr/bin/env perl
eval 'exec /usr/bin/perl  -S $0 ${1+"$@"}'
    if 0; # not running under some shell

=for gpg
Hash: SHA1

=head1 NAME

showPerlDirConfig - explore (pretty-print) the basis of directory loca
of the Perl installation configuration matching the perl interpreter c
being run.

=head2 VERSION

This POD documents

                     * version 2004.01.09 *


 $ showPerlDirConfig
 $ /opt/bin/myfunkyperl showPerlDirConfig


# --------------------------------------------------------------------
# internal CVS - RCS version control information:
## somian ## 1.7 ##
## 2004/01/10 01:54:28    ##
# --------------------------------------------------------------------

use strict;
use Config;
use File::Spec;

$^W       = 1;
$\        = "\n";
my $Ll    = 0;
my $Stogg = 0;

my $headr =
  sub {
      my($perlFQpath,$stringL) = @{&pselfIdentity};
      my $margin = calc_midbuffs ($stringL => $Ll);
      my($decoL,$decoR) = ('','');
      if   ($margin >= 6)
      $decoL = '||:' ; $decoR = ':||';
      my $visi   = "$decoL   $perlFQpath   $decoR";
      my $spadd  = $margin - 3 - length $decoL;
         $spadd += length $visi;
      my $formtl = "%${spadd}s";
      print "Installation directory target configuration for "
       ,"the Perl binary installed as";
      printf $formtl => $visi;
      print "\n\n" , ( '-' x $Ll);

## ***  <main execution> *** ##
print join "\n"
 map { 
     my $keyarr=$_; # we get scoping confusion induced err if not.
     $Stogg++ || &$headr;
     my $ins=$Config::Config{$keyarr->[0]};
     my $ndi=substr($keyarr->[0],0,7) eq 'install'? "\n".('-'x$Ll):'';
     sprintf( "%-20s". " "x8 ."%s$ndi", $keyarr->[0], $ins )
  sort { $a->[1] cmp $b->[1] }
  map [ $_, kenzoku($_) ],
  grep { /^(?!installusr|ta|mv|mu|d_)\w*
         /x } keys %Config::Config
## *** </main execution> *** ##

sub kenzoku  {
    my $mwa=shift;
    my $ins=$Config::Config{$mwa};
    $Ll = ($Ll <= length($ins)+28)? length($ins)+28 : $Ll;
    my $rwa=$mwa;
    $rwa =~s/^install// or $rwa =~s/exp$//;
      $rwa .( substr($mwa,0,7) eq 'install'? 3 :
              substr($mwa,-3)  eq 'exp'?     2 : 1 );

sub pselfIdentity  {
    my $pintexe=$^X;
    unless( $Config::Config{exe_ext}
        substr($pintexe,-4) eq $Config::Config{exe_ext} )
    $pintexe .= $Config::Config{exe_ext};
    unless( File::Spec->file_name_is_absolute($pintexe) ) {
        $pintexe = (grep -x, map File::Spec->catfile($_,$pintexe)
           , split /\Q$Config::Config{path_sep}/, $ENV{PATH})[0];
    return( [$pintexe , length $pintexe] );

sub calc_midbuffs
    my( $textW, $availW ) = @_ ;
    if (    $ENV{'COLUMNS'} and ($ENV{'COLUMNS'} > $availW)
        and ($textW > int(.9 * $availW))    )
    $availW = $ENV{'COLUMNS'};
    my $leew = $availW - $textW;
    return int( ($leew + 0.5) / 2 );



This is a simple program written for the curious Perl newbie or the th
perl administrator (the system admin responsible for the installation 
operating efficiency, and improvement thereof, and upgrades to, Perl..
+.) who
wants to know more about the internal layout of the important director
where Perl parts are kept.

Specifically, the program will display the directories where core and
site-extension perl modules are installed, allowing the prediction of 
yet-to-be built modules are going to land when Perl's module installat
facilities are done with them.

=head2 NOTES

If the F<> file read by your Perl interpreter during operatio
+n is
hosed (incorrect, tampered with, or invalid due to a binary being comp
+iled on
a different system), then the resulting data displayed by this program
cannot be trusted. Garbage in, garbage out.

=head1 SEE ALSO

L<ExtUtils::MakeMaker>, L<Config>, L<perl>


Soren Andersen E<lt>C<somian -AT- pobox *DOT* com>E<gt> a.k.a
E<lt>C<somian -AT- cpan *DOT* org>E<gt> is responsible for all badness
However Perl Monks "castaway" and "Aristotle" helped to point him towa
solutions that led to an improved script.

This release is cryptographically signed. The author / maintainers' Gn
key is identified by No. C<0x4E244EA6> and should be locateable for ve
on keyservers worldwide. "perlsign" (modified code) was used as the si
+gning tool.


Copyright 2003,2004 by Soren Andersen, U.S.A.

This program is Free software; you may redistribute it and/or modify i
+t under the
same terms as Perl itself (See the F<LICENSE> file in your Perl source
+ kit). Part
of that license stipulates that you, the user, agrees that this Free s
+oftware is
accepted "AS-IS" and comes with absolutely NO WARRANTY, not even the i

=head4 Any POD appearing below this line are merely entries for suppor
+t of
L<the CPAN Scripts Repository|> 
+and its automata.

=begin text


=end text

=begin html


=end html




UNIX : System_administration


=begin gpg

Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see


=end gpg

Replies are listed 'Best First'.
Re: showPerlDirConfig
by Aristotle (Chancellor) on Aug 06, 2003 at 17:13 UTC
    Hmm.. am I missing something?
    #!/bin/sh echo -n "`which perl`: " perl -v | grep '^This is' echo perl -V:'^(?!installusr|ta|mv|mu|d_)\w*(?:bin(?!compat)|arch(?!name|ob +j)|priv|(?:vendor|site)(?!lib_|prefix))[a-z]*' | grep -v =\'\'\$
    Not as pretty, but seems to do the same thing?

    Makeshifts last the longest.

      Not as pretty, but seems to do the same thing?

      In this case, my intention was to use the sorting of the output to illustrate in an immediately easy-to-see manner, the relationship between

      sitelib, sitelibexp and installsitelib
      , and then the comparison to the same series for sitearch, for example.

      In this case the "prettiness" is part of the point, and otherwise of course TMTOWTDI. But note that your alternative certainly falls lower on the portability scale since you are relying on the which tool, which is *nix-centric, and won't be present on many MS Windows boxes, as is also true of the grep command. Although I didn't write this tool on M$ Windows, it's certainly my intention that Win32-Perl users can use it as well as *nix-perl users.

      Thanks for your feedback!


      use PerlMonk::Tye qw(:wisely);

        Actually it could easily do without the greps - or I could use perl for the same task.

        Also note that on no system is $PATH searched recursively. Your code does, so may find the wrong binary.

        It still seems excessively convoluted. How about so?

        #!/usr/bin/perl -w use strict; use Config; use File::Spec::Functions qw(catfile file_name_is_absolute); my ($binary) = file_name_is_absolute($^X) ? $^X : ( grep -x, map catfile($_,$^X), split /\Q$Config::Config{path_sep}/, $ENV{PATH} ); my %interesting = map +( $_ => do { (my $rwa = $_) =~ s/^install|exp$//; $rwa . (/^install/ ? 3 : /^exp$/ ? 2 : 1); } ), grep { /^(?!installusr|ta|mv|mu|d_)\w* (?:bin(?!compat)|arch(?!name|obj)|priv| (?:vendor|site)(?!lib_|prefix)) [a-z]* /x } keys %Config::Config; print( "Binary is at: $binary\n\n", map { my $lf = /^install/ ? "\n" : ''; sprintf("%-20s %s\n", $_, $Config::Config{$_}) . $lf; } sort { $interesting{$a} cmp $interesting{$b} } keys %interesting );

        Makeshifts last the longest.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: sourcecode [id://281332]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2017-09-19 22:45 GMT
Find Nodes?
    Voting Booth?
    During the recent solar eclipse, I:

    Results (230 votes). Check out past polls.