Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re^3: showPerlDirConfig

by Aristotle (Chancellor)
on Aug 06, 2003 at 23:12 UTC ( #281639=note: print w/replies, xml ) Need Help??

in reply to Re: showPerlDirConfig
in thread showPerlDirConfig

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.

Replies are listed 'Best First'.
Re^3: showPerlDirConfig
by Intrepid (Deacon) on Aug 07, 2003 at 15:37 UTC

    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.


    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.

        Aristotle wrote:

        No. my ($binary) is list context.

        ++ for being more idiomatic than I. Good follow-up. I must cantankerously contend that since I don't believe perl should parse this way, though, I will still refuse to code with that usage.


        You see, it's too obscure, IMHO. In some contexts, people have thought that merely having parenthesis made a list context, when in fact it is comma operators that are doing so (as per a famous rant by mjd that I have no reference to at this moment); so in my book this idiom is truly obfuscated. Yes, it is handy to have a way to say my ($scalar)= to force a list context, but as syntactic sugar it tastes remarkably sour to my buds. It's a dank dark corner of perl that I want to stay away from.

        Still, very ++ for explaining to me. At least I may remember what I am looking at next time I see it, even if I choose not to use it.


        use PerlMonk::Tye qw(:wisely);

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (2)
As of 2023-09-26 21:51 GMT
Find Nodes?
    Voting Booth?

    No recent polls found