Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Win32::File::SetAttributes not numeric?

by mcarthey (Novice)
on Jun 05, 2009 at 19:16 UTC ( #768895=perlquestion: print w/ replies, xml ) Need Help??
mcarthey has asked for the wisdom of the Perl Monks concerning the following question:

Hello all!

I've tried a few methods of trying to set file attributes, but the result is always the same:

Argument "READONLY" isn't numeric

I've tried setting the value in the following manners:

Method 1:

# get current file attributes Win32::File::GetAttributes($file, my $attr); # set file attributes to allow editing $attr |= READONLY; Win32::File::SetAttributes($file, $attr);
Method 2:
my $setReadOnlyAttribute = READONLY; # set file attributes to allow editing Win32::File::SetAttributes($file, $setReadOnlyAttribute);
The $file value contains the path and filename. It appears obvious that the problem is the READONLY value, but I don't see how else to set this. I've searched but haven't been able to come up with anyone having the same problem. I thought perhaps READONLY was incorrectly defined, so have also tried other values such as NORMAL, and HIDDEN, but I have the same issue.

Thanks for any insight!

Comment on Win32::File::SetAttributes not numeric?
Select or Download Code
Re: Win32::File::SetAttributes not numeric?
by afoken (Parson) on Jun 05, 2009 at 19:25 UTC

    Looks like perl thinks READONLY is a bareword, not a constant. use Win32::File; should automatically import those constants. Show us your code, especially the part that loads Win32::File.

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
Re: Win32::File::SetAttributes not numeric?
by mcarthey (Novice) on Jun 05, 2009 at 19:36 UTC

    Sorry to bother all... but after hours of looking at this I finally figured it out, although I don't completely understand the reason.

    I simply moved the use Win32::File; line from the top of my code to the subroutine in which it was used.

    Thanks!

      Bad fix. The use needs to be in the same package, but it putting in the sub looses readability and maintainability points.

      By the way, use use strict; use warnings;!!

        I am currently using the pragmas use strict; use warnings; use diagnostics;

        I'd much prefer to keep the use Win32::File;at the top of the package, but apparently my module doesn't like that.

        The subroutine contains the following:

        my $setROattr = READONLY; my $unsetROattr = ~READONLY; # set file attributes to allow editing Win32::File::SetAttributes($file, $unsetROattr);
        .. and the error with use Win32::File; at the top of the package is still...
        Argument "READONLY" isn't numeric in subroutine entry
        Thanks for the help!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://768895]
Approved by ikegami
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (14)
As of 2014-08-20 18:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (121 votes), past polls