mosh has asked for the wisdom of the Perl Monks concerning the following question:

Fellow Monks,

I have Perl script that takes a file from RootDir:

my $listener = Net::TFTPd->new('RootDir' => 'c:/', ...
How do I take the file from the current working directory, meaning, from the directory I run the .pl script?
What should I write in the RootDir value instead of 'c:/'?

(Added after 2 hours)
Guys where are all your creative ideas ??? Anyone??

Mosh.

Replies are listed 'Best First'.
Re: Taking file from current working directory
by polettix (Vicar) on May 23, 2005 at 12:31 UTC
    Cwd should help you in a portable way.

    Flavio (perl -e 'print(scalar(reverse("\nti.xittelop\@oivalf")))')

    Don't fool yourself.
      Thanks for the suggestion, but Cwd doesn't work on Win32 OS, as written in the CPAN testers:
      http://testers.cpan.org/show/PathTools.html#PathTools-3.07

      Any other ideas?

      Mosh.

        Well, if all you want is cwd, why don't you install the Cwd module? The current version seems to pass on all OS's (and I use it myself under Windows.)

        Cwd is a core module, which means it comes with perl. You already have Cwd. cpan-testers results can't be taken at face value, especially a vague report like http://www.nntp.perl.org/group/perl.cpan.testers/204675. It looks like that reporter doesn't have a compiler, so there is no chance he could ever successfully build Cwd.
      That doesn't help at all. The OP does not what the current working directory is, so he can't cwd there.

      Update: striked. Looks like I am a dumb today.



      holli, /regexed monk/
        Uh?
        This module provides functions for determining the pathname of the current working directory. It is recommended that getcwd (or another *cwd() function) be used in all code to ensure portability.
        Seems a little more portable than "./", but I might be missing something.

        Update: ah, maybe I understand now. CWD stands for "Current Working Directory", the function tho change directory in Perl is chdir. That's what maybe misguided you.

        Flavio (perl -e 'print(scalar(reverse("\nti.xittelop\@oivalf")))')

        Don't fool yourself.
Re: Taking file from current working directory
by holli (Abbot) on May 23, 2005 at 11:55 UTC
    simple, just leave away the path part
    my $listener = Net::TFTPd->new('RootDir' => 'filename',...);


    holli, /regexed monk/
      Nope,

      I've already tried it without success, I've got an error message:
      "Cannot create listener. RootDir '1.txt' is not a valid directory name

      Any other ideas ?

      I need somehow to write the current working directory...

      Mosh.

        Try
        my $listener = Net::TFTPd->new('RootDir' => './',...);
        Update:
        Ah, I misread the OP.


        holli, /regexed monk/
Re: Taking file from current working directory
by jpeg (Chaplain) on May 23, 2005 at 12:34 UTC
    How about $ENV{PWD} ?
    --
    jpg
      I develop on Win32 OS, so either PWD or './' isn't relevant...

      Mosh.

        the dot "." represents the current working directory, even on Win32. Also Perl handles both kinds of slashes transparently.


        holli, /regexed monk/
Re: Taking file from current working directory
by tlm (Prior) on May 24, 2005 at 03:22 UTC

    I don't know how portable it is but FindBin has been bery-bery good too me. You could try:

    use FindBin '$RealBin'; my $listener = Net::TFTPd->new(RootDir => $RealBin,...

    Also, be lazy! Accept auto-quoting (before "=>"s) into your life.

    the lowliest monk