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

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2021-12-06 06:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    R or B?



    Results (31 votes). Check out past polls.

    Notices?