use Fcntl qw(
O_CREAT
O_RDWR
);
sysopen(FILE, "$file", O_RDWR|O_CREAT, 0755)
...
He who asks will be a fool for five minutes, but he who doesn't ask will remain a fool for life.
Chady | http://chady.net/ | [reply] [d/l] |
In addition to the above advice, you should learn about umask.
umask determines what mode bits will be set on a newly created file by default. What happens is, the systems starts with bits 0777 (full permissions), and subtracts the bits that are set in your umask. The result is used as the default mode for new files.
So, basically, if you want to have all the execute bits set, make sure the corresponding bits are unset (0) in your umask.
For example, if you want a mode of 0751 by default, then set your umask to 0026.
jdporter ...porque es dificil estar guapo y blanco. | [reply] |
In addition to looking at the sysopen docs as indicated above, you might also find it useful to read perlopentut section "Open à la C" and particularly the next section "Permissions à la mode".
Okay you lot, get your wings on the left, halos on the right. It's one size fits all, and "No!", you can't have a different color.
Pick up your cloud down the end and "Yes" if you get allocated a grey one they are a bit damp under foot, but someone has to get them.
Get used to the wings fast cos its an 8 hour day...unless the Govenor calls for a cyclone or hurricane, in which case 16 hour shifts are mandatory.
Just be grateful that you arrived just as the tornado season finished. Them buggers are real work.
| [reply] |
I'm not sure what you mean by "all at once." As others have pointed out, you can use sysopen() but you have to concern yourself with the process umask when you do. It's probably better just to open the file, write it, close it, and then set the permissions with Perl's chmod() function.
-sauoq
"My two cents aren't worth a dime.";
| [reply] |
yea.. that's what i'm looking for.. guess i was tired. :)-Lisa
| [reply] |
Okay, wolverina, now that you know the how, it's time to deal with the whether. Please consider the security implications of letting someone upload a file and, just because it has a .pl extension, automatically making it executable. Who gets to upload such a file? Where does it get written? Who gets to execute the code once uploaded? What if the code is malicious? It seems like such a small thing, but setting permissions in such a way can open a Pandora's box of tribulation. Please be careful. | [reply] |