http://www.perlmonks.org?node_id=1043882


in reply to Re: listing all files of a dir
in thread listing all files of a dir

thanks for replying , just one more thing how to point to the current directory as in
opendir(my $dh, $some_dir) || die;

instead of $somedir , how can we have present directory

Replies are listed 'Best First'.
Re^3: listing all files of a dir
by davido (Cardinal) on Jul 12, 2013 at 06:30 UTC

    use Cwd

    These questions are searchable.


    Dave

Re^3: listing all files of a dir
by kcott (Archbishop) on Jul 12, 2013 at 06:32 UTC

    You can use Cwd for that.

    -- Ken

      no I did getcwd , but I am on windows , so it gives error stating "unidentified subroutine "

        -- vote for not providing enough information for us to avoid giving advice that you already have discovered doesn't work for you.

        ...although... I don't have a handy copy of Windows here, but I have to wonder why the documentation for Cwd contradicts your experience:

        The getdcwd() function is also provided on Win32 to get the current working directory on the specified drive, since Windows maintains a separate current working directory for each drive. If no drive is specified then the current drive is assumed.

        This function simply calls the Microsoft C library _getdcwd() function.


        Dave

        For some reason, the name of the current directory is always '.'

        use strict; use warnings; use Cwd; my $dir=getcwd; say $dir;

        ...works as documented under 5.16 and W7. It's likely you erred somewhere in your code. Note the first two lines of the snippet above.

        If I've misconstrued your question or the logic needed to answer it, I offer my apologies to all those electrons which were inconvenienced by the creation of this post.