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

$dir = "./";
Please explain what the "./" represents here? I assume it means present working directory? If so how would I rewrite this to take an input?
$dir = "./"; opendir( DIRS, $dir );
I tried:
Print "Enter directory"; $dir=<STDIN>; chomp $dir; opendir (DIRS, $dir);

Replies are listed 'Best First'.
Re: Changing to input
by zejames (Hermit) on Jul 03, 2002 at 12:52 UTC
    Your code is right, you just don't check for errors after try to open the directory:
    Print "Enter directory : "; chomp($dir = <STDIN>); opendir DIR, $dir or die "Unable to open directory $dir : $!\n"; @files = grep { !/\.\.?/ } readdir DIR; print "$dir contains " . join(',', @files);

    HTH


    --
    zejames
      I understand all except this part?? What is "join" doing here?? print "$dir contains " . join(',', @files);

        It produces a string that contains all of its arguments, separated by the first one. In this case, it takes all the @files, puts commata between them, and makes that one large string.

        If you don't know what something does, you can look it up in the extensive perldoc. Try perldoc -f join on the commandline and see what it tells you. If you're using ActiveState Perl on Windows, you will probably want to find the HTML version of the documentation it ships with and installs. There is hardly any trivial question you cannot answer straight off the docs within a minute.

        Makeshifts last the longest.

Re: Changing to input
by Zaxo (Archbishop) on Jul 03, 2002 at 12:54 UTC

    Print is not capitolized. You will need to call readdir once you have *DIR open.

    Yes, ./ represents the pwd.

    After Compline,
    Zaxo