Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

chmod in perl

by Anonymous Monk
on Mar 11, 2011 at 04:26 UTC ( #892582=perlquestion: print w/replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I am opening a file for writing,but if the if the file already exists in read-only mode,am getting a "permission denied" error,I tried to add below,it didnt work,any inputs?

chmod 0777 deletefiles.txt; open(my $OUTPUT, '+>', "deletefiles.txt") or die $!;

Replies are listed 'Best First'.
Re: chmod in perl
by atcroft (Abbot) on Mar 11, 2011 at 04:33 UTC

    Have you checked the return status of the chmod command? For instance,

    my $filename = q{deletefiles.txt}; chmod 0777, $filename or die $!; open my $OUTPUT, q{+>}, $filename or die $!;

    Hope that helps.

    Update: 2011-03-11

    Fixed missing semicolon on line 2 of code example causing error referred to in Re^2: chmod in perl.

      I am getting the following error with the above code

      my $filename = q{deletefiles.txt}; chmod 0777, $filename or die $! open my $OUTPUT, q{+>}, $filename or die $!; Missing comma after first argument to die function at line 135 +, near "$filename or" Execution of aborted due to compilation errors.
        You miscopied the code.
        Try and put the semicolon after first die statement. Because of that its throwing that error because it's gonna continue till the end of file if you dont specify where to exactly end.
Re: chmod in perl
by graff (Chancellor) on Mar 11, 2011 at 05:34 UTC
    If you happen to be on a unix/linux system (which is pretty much the only place where chmod makes sense), you should be aware that chmod will fail when used on a file that is not owned by the user who is running the script. (update: unless of course the user happens to be "root" -- in which case the user really ought to know what s/he is doing...)

    As mentioned above, checking the return value (and printing the value of $! when chmod returns false) will help you figure out what is going on.

Re: chmod in perl
by ikegami (Pope) on Mar 11, 2011 at 04:33 UTC

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://892582]
Approved by ikegami
[Discipulus]: yes I saw and i go to the tranlsator, but i supposed to be a pun, a normal sink in a normal roof.. congrats to our sister if so!
[Discipulus]: Insula Mona? they have the same flag of Sicily.. curious
[1nickt]: The Romans were everywhere!

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (9)
As of 2017-11-21 12:04 GMT
Find Nodes?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:

    Results (299 votes). Check out past polls.