Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: showPerlDirConfig

by Aristotle (Chancellor)
on Aug 06, 2003 at 17:13 UTC ( [id://281506]=note: print w/replies, xml ) Need Help??


in reply to showPerlDirConfig

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.

Replies are listed 'Best First'.
Re: showPerlDirConfig
by Intrepid (Deacon) on Aug 06, 2003 at 20:00 UTC

    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!

        me

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

        Aristotle wrote:

        my ($binary) = file_name_is_absolute($^X) ? $^X : ( grep -x, map catfile($_,$^X), split /\Q$Config::Config{path_sep}/, $ENV{PATH} );

        As far as I can see, you are calling grep in a scalar context and would normally be putting "1" (0x1) into $binary using this code. Am I wrong?

        I (being the one who has to maintain this code) kept to my own version of what is less convoluted / obfuscated, but have added credits in the POD for pointing me towards a better code block for getting the fully-qualified path to the perl interpreter. Thank you.

            me

        -- 
        use PerlMonk::Tye qw(:wisely);
        

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (7)
As of 2024-04-18 06:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found