Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^3: showPerlDirConfig

by Intrepid (Deacon)
on Aug 07, 2003 at 15:37 UTC ( [id://281930]=note: print w/replies, xml ) Need Help??


in reply to Re^3: showPerlDirConfig
in thread showPerlDirConfig

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

Replies are listed 'Best First'.
Re^5: showPerlDirConfig
by Aristotle (Chancellor) on Aug 07, 2003 at 15:47 UTC
    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.

      Tangent:

      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.

          me

      -- 
      use PerlMonk::Tye qw(:wisely);
      
        Sure.
        my $binary = file_name_is_absolute($^X) ? $^X : ( grep -x, map catfile($_,$^X), split /\Q$Config::Config{path_sep}/, $ENV{PATH} )[0];

        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://281930]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2024-04-20 04:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found