Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: showPerlDirConfig

by Intrepid (Deacon)
on Aug 06, 2003 at 20:00 UTC ( [id://281565]=note: print w/replies, xml ) Need Help??


in reply to Re: showPerlDirConfig
in thread showPerlDirConfig

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);

Replies are listed 'Best First'.
Re^3: showPerlDirConfig
by Aristotle (Chancellor) on Aug 06, 2003 at 23:12 UTC

    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);
      
        No. my ($binary) is list context. my $binary would be scalar context. So what happens here is that the first match from the grep is stored in $binary and the rest, if any, are discarded.

        Makeshifts last the longest.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2024-04-16 15:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found