Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Actually FindBin is broken in more than just this way. I've had cases where scripts that had limited permissions (CGI), where FindBin just died. It looks like it tries to verify the existence of the path it found, occasionally ending up in directories where it has no visiting rights. I'm not sure that is indeed what it does, — if so, it's likely File::Spec that is to blame; but this situation makes it useless for situations where it would be most useful.

Anyway, to answer your question: yes, $0 would be set to ..\..\script.pl. That's where tye's solution, rel2abs, would again come to the rescue. A demo of a full solution, as tye merely mentioned the function name:

use File::Spec::Functions 'rel2abs'; print rel2abs($0);

update: Oh dear, it doesn't. The double dots are still in the created path. For Unix, that is the safest, as you never know which "directory" is actually just a link to another directory, so by following "foo/.." you could end up in an entirely different directory from where you started from.

It doesn't look as neat, but it works just as well.


In reply to Re: Re: Re: Find the full path of the script at run time by bart
in thread Find the full path of the script at run time by ibanix

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (1)
As of 2024-04-25 00:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found