current path

Discussion in 'Perl Misc' started by Jochen Friedmann, Sep 17, 2003.

  1. Hello together,

    how can I find the current path my Perlscript is started ?

    Jochen
     
    Jochen Friedmann, Sep 17, 2003
    #1
    1. Advertising

  2. In article <bk9jel$nic$>, Jochen Friedmann wrote:
    > how can I find the current path my Perlscript is started ?


    See the documentation for the FindBin module.


    --
    Andreas Kähäri
     
    Andreas Kahari, Sep 17, 2003
    #2
    1. Advertising

  3. Jochen Friedmann

    Thens Guest

    "Jochen Friedmann" <> wrote:

    # how can I find the current path my Perlscript is started ?

    I dont know what you meant by the current path.

    If it is the current directory, you can get the current working
    directory like this

    use Cwd;
    my $dir = cwd();

    You can get the full path to the script name from the variable $0 and
    then if you do a basename on it you can get the path to the directory
    where the script is present.

    example :
    script : /home/abc/scripts.pl

    #!/usr/bin/perl

    use strict;
    use warnings;
    use File::Basename;
    my $dir = File::basename($0);

    --
    Thens.
     
    Thens, Sep 17, 2003
    #3
  4. Jochen Friedmann

    Paanwa Guest

    "Jochen Friedmann" <> wrote in message
    news:bk9jel$nic$...
    > Hello together,
    >
    > how can I find the current path my Perlscript is started ?
    >
    > Jochen
    >
    >


    You can also get this information from Environment Variables....check out
    http://www.devdaily.com/perl/edu/articles/pl020001.shtml

    PAW
     
    Paanwa, Sep 17, 2003
    #4
  5. Paanwa <> wrote:
    > "Jochen Friedmann" <> wrote in message
    > news:bk9jel$nic$...



    >> how can I find the current path my Perlscript is started ?



    > You can also get this information from Environment Variables....check out
    > http://www.devdaily.com/perl/edu/articles/pl020001.shtml



    Perl is not CGI.

    The OP made no mention of what environment his Perl program runs in...


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Sep 17, 2003
    #5
  6. Jochen Friedmann wrote:
    > how can I find the current path my Perlscript is started ?


    Please define "current path".

    If you are talking about the current working directory, then please have a
    look at Cwd::cwd.
    If you are talking about the location of the Perl script in your filesystem,
    then please check $FindBin::Bin.
    Or $0.

    Either of them may or may not work for your specific requirements.

    jue
     
    Jürgen Exner, Sep 18, 2003
    #6
  7. > how can I find the current path my Perlscript is started ?


    use Cwd;
    my $pwd = cwd; $pwd =~ s!/!\\!g;
    print "Current path is $pwd\n";

    --
    R.
    GPLRank +79.699
     
    Richard S Beckett, Sep 18, 2003
    #7
  8. Jochen Friedmann

    Paanwa Guest


    > Perl is not CGI.
    >
    > The OP made no mention of what environment his Perl program runs in...


    Hi Tad,

    Thanks for pointing this out. I've not yet seen an environment with ENV
    can't return the script path - there are always exceptions. Can anyone tell
    me if there are performance consideration in using ENV vs Cwd?

    PAW
     
    Paanwa, Sep 18, 2003
    #8
  9. Paanwa <> wrote:
    >
    >> Perl is not CGI.
    >>
    >> The OP made no mention of what environment his Perl program runs in...

    >
    > Hi Tad,
    >
    > Thanks for pointing this out.



    Is your Perl programming running in the CGI environment or is it not?


    > I've not yet seen an environment with ENV
    > can't return the script path -



    I have no idea what you are talking about.

    We have asked you before to clarify what you meant by "script path",
    please try and do that.

    I can't tell if you want the current working directory, or the
    location of your program file in the filesystem, or the URL for
    some CGI program.

    Which one is it that you are trying to find?

    There are potentially lots and lots of environment variables,
    which one is it that you are talking about? I assumed it
    was $ENV{PWD}...


    > there are always exceptions. Can anyone tell
    > me if there are performance consideration in using ENV vs Cwd?



    Now I am even more confused about what it is that you are asking.

    If you are asking about the "current working directory", then why
    do you keep mentioning the location of the program file?

    Where your program file exists in the filesystem is not related
    to what your current working directory is.

    We must understand what you are asking for before we can help
    you find it.

    Try again explaining what it is that you are asking for.


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Sep 18, 2003
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Manu
    Replies:
    1
    Views:
    6,111
    Natty Gur
    Jul 20, 2003
  2. Matthew Heidemann
    Replies:
    14
    Views:
    251
    eT Ma
    Mar 22, 2011
  3. Replies:
    3
    Views:
    182
  4. Jack
    Replies:
    3
    Views:
    617
    Tad J McClellan
    Dec 22, 2008
  5. Replies:
    3
    Views:
    394
Loading...

Share This Page