the following piece of code, is working fine, but I have my doubts about some of the stuff i do in it...
use POSIX; use File::Copy; use strict; my $serverdir="/kode/perlstuff/test/"; # function for copying all files and directories recursivly with new r +ead only permissions sub copyrecursivly{ my $p_source=shift; my $p_destination=shift; if (-d $p_source){ mkdir $p_destination,"0755"; opendir(datadir,$p_source); foreach my $tempvalue (grep {!/^\./} readdir(datadir)){ copyrecursivly($p_source . "/" . $tempvalue,$p_destination . " +/" . $tempvalue); } closedir(datadir); }else{ copy($p_source, $p_destination); } } # Check that the BACKUP/ directory is present, otherwise create it if (!opendir(backupdir,$serverdir . "BACKUP/")){ mkdir $serverdir . "BACKUP/" , "0755"; opendir(backupdir,$serverdir . "BACKUP/") or die "could not create + backup directory!"; } closedir(backupdir); # Open the server directory, and create the backup destination directo +ry opendir(datadir,$serverdir) or die "could not open server directory!"; my $destinationdir=$serverdir . "BACKUP/dailyimage_" . POSIX::strftime + "%Y-%d-%m", localtime; mkdir $destinationdir; # Copy all files from source to destination foreach my $tempvalue (grep {!/^\.|[BACKUP]/ } readdir (datadir)){ copyrecursivly($serverdir . $tempvalue,$destinationdir . "/" . $te +mpvalue); } closedir(datadir);
ok first of all... for my normal variables i use my within my recursive function, which should make them safe... but what about my file handles? The code works fine, but since I read all data from the filehandles before i recurse further, it should work fine even if my filehandle names are within the same scope... but then my closedir statements are not closing all opened directories... which they should! So my question is, are they within in the same scope? and if so, how do i make them local to the function?
Next question... am I giving the right parameters to mkdir inorder to achieve 755 rights on the directory?
Final question... is there anything in this piece of code which i ought to do differently?
thanks Kasper
In reply to bag of questions... by kapper
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |