> -----Original Message-----
> From: Brian Ling [mailto:[EMAIL PROTECTED]] 
> Sent: Tuesday, January 21, 2003 10:59 AM
> To: NYIMI Jose (BMB); Mark Goland
> Cc: perl
> Subject: RE: Path to script
> 
> 
> Thanks for that,
> 
> I'll go with the File::Basename option as I may need to 
> change the 'pwd' by the time the call is made.

Be aware that $0 doesn't always contains the full path of your script
Example: myhost:> ./myscript.pl
Running a script with above command line, $0 will be ./myscript.pl
So File::Basename will no longer help.

So I suggest you using FindBin module instead:

C:\>perldoc FindBin
NAME
    FindBin - Locate directory of original perl script

SYNOPSIS
     use FindBin;
     use lib "$FindBin::Bin/../lib";

     or

     use FindBin qw($Bin);
     use lib "$Bin/../lib";

DESCRIPTION
    Locates the full path to the script bin directory to allow the use of
    paths relative to the bin directory.

    This allows a user to setup a directory tree for some software with
    directories <root>/bin and <root>/lib and then the above example will
    allow the use of modules in the lib directory without knowing where the
    software tree is installed.

    If perl is invoked using the -e option or the perl script is read from
    "STDIN" then FindBin sets both "$Bin" and "$RealBin" to the current
    directory.

EXPORTABLE VARIABLES
     $Bin         - path to bin directory from where script was invoked
     $Script      - basename of script from which perl was invoked
     $RealBin     - $Bin with all links resolved
     $RealScript  - $Script with all links resolved

KNOWN BUGS
    if perl is invoked as

       perl filename

    and *filename* does not have executable rights and a program called
    *filename* exists in the users "$ENV{PATH}" which satisfies both -x and
    -T then FindBin assumes that it was invoked via the "$ENV{PATH}".

    Workaround is to invoke perl as

     perl ./filename

AUTHORS
    FindBin is supported as part of the core perl distribution. Please send
    bug reports to <[EMAIL PROTECTED]> using the perlbug program included
    with perl.

    Graham Barr <[EMAIL PROTECTED]> Nick Ing-Simmons <[EMAIL PROTECTED]>

COPYRIGHT
    Copyright (c) 1995 Graham Barr & Nick Ing-Simmons. All rights reserved.
    This program is free software; you can redistribute it and/or modify it
    under the same terms as Perl itself.

> 
> Brian 
> 
> -----Original Message-----
> From: NYIMI Jose (BMB) [mailto:[EMAIL PROTECTED]] 
> Sent: 21 January 2003 09:48
> To: Mark Goland; Brian Ling
> Cc: perl
> Subject: RE: Path to script
> 
> 
> Have a look to :
> 
> http://search.cpan.org/author/LIBERTY/Cwd-2.06/Cwd.pm
> 
> José.
> 
> 
> > -----Original Message-----
> > From: Mark Goland [mailto:[EMAIL PROTECTED]]
> > Sent: Tuesday, January 21, 2003 10:42 AM
> > To: Brian Ling
> > Cc: perl
> > Subject: Re: Path to script
> > 
> > 
> > my $path=`pwd` on *nix
> > my $path=`cd` on win*
> > 
> > ----- Original Message -----
> > From: "Brian Ling" <[EMAIL PROTECTED]>
> > To: <[EMAIL PROTECTED]>
> > Sent: Tuesday, January 21, 2003 4:25 AM
> > Subject: Path to script
> > 
> > 
> > > Hi all,
> > > 
> > > I have the following bit of code that works out the
> > directory path to
> > > the currently executing script.
> > > 
> > > My $path = $0;
> > > $path =~ s#(^/.+/).+$#$1# ;
> > > 
> > > This works but doesn't make me happy, is there a better way?
> > > 
> > > Thanks
> > > 
> > > Brian
> > > 
> > > 
> > > 
> > > BBCi at http://www.bbc.co.uk/
> > > 
> > > This e-mail (and any attachments) is confidential and may contain
> > > personal views which are not the views of the BBC unless
> > specifically
> > > stated.
> > > If you have received it in error, please delete it from
> > your system, do
> > > not use, copy or disclose the information in any way nor act in 
> > > reliance on it and notify the sender immediately. Please
> > note that the
> > > BBC monitors e-mails sent or received. Further communication will 
> > > signify your consent to this.
> > > 
> > > 
> > 
> > --
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> > 
> > 
> 
> 
> **** DISCLAIMER ****
> 
> "This e-mail and any attachment thereto may contain 
> information which is confidential and/or protected by 
> intellectual property rights and are intended for the sole 
> use of the recipient(s) named above. 
> Any use of the information contained herein (including, but 
> not limited to, total or partial reproduction, communication 
> or distribution in any form) by other persons than the 
> designated recipient(s) is prohibited. 
> If you have received this e-mail in error, please notify the 
> sender either by telephone or by e-mail and delete the 
> material from any computer".
> 
> Thank you for your cooperation.
> 
> For further information about Proximus mobile phone services 
> please see our website at http://www.proximus.be or refer to 
> any Proximus agent.
> 
> 
> 
> BBCi at http://www.bbc.co.uk/
> 
> This e-mail (and any attachments) is confidential and may contain 
> personal views which are not the views of the BBC unless specifically 
> stated.
> If you have received it in error, please delete it from your 
> system, do 
> not use, copy or disclose the information in any way nor act in 
> reliance on it and notify the sender immediately. Please note 
> that the 
> BBC monitors e-mails sent or received. Further communication will 
> signify your consent to this.
> 
> 

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to