$^X 
Author Message
 $^X

Hi,

If I do:

% perl -e 'print "$^X\n";'

under most circumstances I'll get '/usr/local/bin/perl' or whatever.
If I do it when the perl executable is in /usr/bin/perl then I just
get 'perl' . How can I guarantee to get the full path to the executable?

This is happening with  perl 5.00503 under solaris 8.

cheers, Jim Lewis

-------------------------------------------------------------------------------

  Jim Lewis                        |
  Cambridge Astronomy Survey Unit  | Phone (direct)    44-(0)1223-766652

  Institute of Astronomy           |       (reception) 44-(0)1223-337548

  Madingley Road                   | FAX               44-(0)1223-337523

  Cambridge CB3 0HA                |

-------------------------------------------------------------------------------



Mon, 27 Jan 2003 03:00:00 GMT  
 $^X

Quote:
>If I do:

>% perl -e 'print "$^X\n";'

>under most circumstances I'll get '/usr/local/bin/perl' or whatever.
>If I do it when the perl executable is in /usr/bin/perl then I just
>get 'perl' . How can I guarantee to get the full path to the executable?

>This is happening with  perl 5.00503 under solaris 8.

 From perldoc perlvar:

         ...
              $EXECUTABLE_NAME

              $^X     The name that the Perl binary itself was executed
                      as, from C's `argv[0]'.  This may not be a full
                      pathname, nor even necessarily in your path.
         ...

So it doesn't seem that it's possible to assure the path to the perl
executable using $^X.

My PATH includes /usr/local/bin and that is the location of my perl binary
(5.6.0) and this is what I get on your one-liner:

         $ perl -e 'print "$^X\n";'
         perl
         $

If you need to know the full path to the perl executable, then you probably
want to use the Config module.  But be warned that this isn't fool-proof
either.  From perldoc Config:

         ...
         WARNING
              Because this information is not stored within the perl
              executable itself it is possible (but unlikely) that the
              information does not relate to the actual perl binary which
              is being used to access it.

              The Config module is installed into the architecture and
              version specific library directory ($Config{installarchlib})
              and it checks the perl version number when loaded.
         ...
              `perlpath'
                  From perlpath.U:

                  This variable contains the eventual value of the
                  `PERLPATH' symbol, which contains the name of the perl
                  interpreter to be used in shell scripts and in the "eval
                  `exec'" idiom.

Here's what my system has to say:

         $ perl -MConfig -e 'foreach ( keys %Config ) { print
"$_=$Config{$_}\n"; }' | grep /usr/local/bin
         bin=/usr/local/bin
         binexp=/usr/local/bin
         installbin=/usr/local/bin
         installscript=/usr/local/bin
         installsitebin=/usr/local/bin
         pager=/usr/local/bin/less
-->     perlpath=/usr/local/bin/perl
         scriptdir=/usr/local/bin
         scriptdirexp=/usr/local/bin
         sitebin=/usr/local/bin
         sitebinexp=/usr/local/bin
         startperl=#!/usr/local/bin/perl
         $

Hope this helps.

-Garry Williams



Mon, 27 Jan 2003 03:00:00 GMT  
 $^X
I heard this news group was dead; so I thought
I would post -


What dos this match?

I think it matches:













Anything I missed?  Also, is this the right syntax?

???
- FCCJ * 501 W State St * Jacksonville, Fl 32202 * 904/632-3089 -



Sun, 09 Feb 2003 03:00:00 GMT  
 $^X

Quote:
>I heard this news group was dead; so I thought
>I would post -


>What dos this match?

>I think it matches:













>Anything I missed?  Also, is this the right syntax?

yeah .. all of the above with mixed case .. and (just in case you didn't
realise) any of the above appearing anywhere in another line

to answer your ?: question .. this prevents the enclosing parens from
capturing data .. which means that the above also initialises the
following vars (for the first example you provided)


  $2 = 'usa'
  $3 = 'net'

--



Sun, 09 Feb 2003 03:00:00 GMT  
 $^X

Quote:

> Sent: Wednesday, August 23, 2000 12:03

> Subject: ?: operator

> I heard this news group was dead; so I thought
> I would post -


> What dos this match?

> I think it matches:













> Anything I missed?  Also, is this the right syntax?

It matches any upper-case letters too, and arbitrary preceding and
succeeding characters (because there are no anchors).

It has an odd combination of capturing and non-capturing parentheses.

All in all, I'm not sure what you wanted to achieve by asking this
question, other than assurance that the newsgroup isn't dead.  Moribund,
perhaps, though...

--
Larry Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/



Sun, 09 Feb 2003 03:00:00 GMT  
 $^X

Quote:

> I heard this news group was dead; so I thought
> I would post -


> What dos this match?

> I think it matches:













> Anything I missed?  Also, is this the right syntax?

Or anything with one of these as a substring

Also, the use of (?:...) seems a bit strange as you have only used it
for one set of parentheses.

--
Ren Maddox



Sun, 09 Feb 2003 03:00:00 GMT  
 $^X

Quote:

> I heard this news group was dead; so I thought I would post

An interesting approach. I hadn't heard it was dead, but what do I know?

Quote:


> What dos this match?

> I think it matches:













> Anything I missed?

Well, your examples don't include anything mixed case: it will match

Quote:
> Also, is this the right syntax?

If perl doesn't give a syntax error (and it doesn't) then there isn't a
syntax error in the regexp. Guessing, based on the subject line, I'll
add this:/(?:anything)/ /acts identically to /(anything)/ except that it
isn't a backreference: it doesn't save the encapsulated 'anything', and
it doesn't increment the count of backreferences.

So your regexp delivers these three backreferences:

  $2: usa|fccj
  $3: org|net|edu|com



result in (undef, undef, 'edu').

E&OE,

Hugo



Mon, 10 Feb 2003 09:05:56 GMT  
 $^X

Quote:


>>Anything I missed?  Also, is this the right syntax?

>yeah .. all of the above with mixed case .. and (just in case you didn't
>realise) any of the above appearing anywhere in another line

>to answer your ?: question .. this prevents the enclosing parens from
>capturing data

And of course, despite the subject line, this regex syntax
has nothing to do with the ?: *operator* (aka the ternary
or conditional operator).

--

Washington, DC



Mon, 10 Feb 2003 03:00:00 GMT  
 
 [ 11 post ] 

 Relevant Pages 
 

 
Powered by phpBB® Forum Software