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

I just installed Win32::Perms for an ActiveState install of Perl on a Win2K machine. It seems to be causing a problem that I can't track down. This peice of code works fine:
#!c:\perl\bin\perl.exe -w use strict; use warnings; opendir(DIR, "c:\\") || die "can't opendir c:\\ ( $! ) \n"; my @rootlist = grep {/.*?/ && -d "c:\\$_" } readdir(DIR); closedir DIR; exit;
However, the following code:
#!c:\perl\bin\perl.exe -w use strict; use warnings; use Win32::Perms; opendir(DIR, "c:\\") || die "can't opendir c:\\ ( $! ) \n"; my @rootlist = grep {/.*?/ && -d "c:\\$_" } readdir(DIR); closedir DIR; exit;
Produces this error:
Can't use string ("2") as a synbol ref while "strict refs" in use at t +est.pl line 8.
Line 8 is: opendir(DIR, "c:\\") || die "can't opendir c:\\ ( $! ) \n";
If I don't use strict; , there is no error, but there must be a better answer than that. Any ideas??

Replies are listed 'Best First'.
Re: Strange problem with Win32::Perms
by BrowserUk (Patriarch) on Oct 05, 2003 at 04:59 UTC

    Win32::Perms autoexports various constants for use in conjunction with its methods. The problem is that one of those constants is (unhelpfully) named DIR -- which apparantly has the value 2.

    The simplest work-around is to use a different name than DIR for your directory handle.

    Alternatively, you could use a lexical filehandle my $DIR on the opendir and $DIR elsewhere.


    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller
    If I understand your problem, I can solve it! Of course, the same can be said for you.

      Thanks, that took care of it. Unfortunately, I am having trouble finding good documentation for the module. The info I can find on roth.net is geared more towards an understanding of the win security model than the specifics of the module itself and I can't find the module on cpan.org. Perhaps I will buy the book that is the answer to "Need More Documentation?" on roth.net.

        Probably the best single piece of documentation with the module is the README file contained in the distribution. There are a few very simple examples about half way down.

        Beyond that, the key to understanding how to use the module, is to understand the Win32 Permissions model. It is a very powerful, but also very complex beast. The book would probably be a good way to getting an understanding of the module and how to use it, but don't be surprised if it has to go into quite a lot of detail of the OS security model to do it.

        Whilst you wait for the book to arrive, you could try the MS documentation....here is as good a starting point as any.

        Good luck.


        Examine what is said, not who speaks.
        "Efficiency is intelligent laziness." -David Dunham
        "When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller
        If I understand your problem, I can solve it! Of course, the same can be said for you.

        ChrisR,
        I tried perldoc Win32::Perms and came up with nada. Then I started looking for documentation and got lucky. There is a README file installed with lot's of valuable information such as a FAQ. The list of constants and usage information about the module is all in the FAQ.

        Cheers - L~R