Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

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!

Replies are listed 'Best First'.
Re: Win32::File::SetAttributes not numeric?
by afoken (Abbot) 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.


    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.


      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?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://768895]
Approved by ikegami
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2018-02-24 10:55 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (310 votes). Check out past polls.