Simple filesystem operations in perl
I would like to create a new directory that its content is soft links to the the content of an existing directory, and set full permissions for this new directory.
I know how to this is in bash:
mkdir -m a=rwx new_dir
cd new_dir
ln -s /path/to/old/dir/* .
but having some 开发者_Go百科problems with finding the perl equivalent
How about something like this:
mkdir -m a=rwx new_dir     in perl: ->    mkdir ('new_dir', 0777);
cd new_dir                 in perl: ->    chdir ('new_dir');
ln -s /path/to/old/dir/* . in perl: ->
    use constant OLD_DIR => '/path/to/old/dir';
    for my $oldname (glob(OLD_DIR . '/*')) {
         my $newname = $oldname;
         $newname =~ s/^.*\///s;      # Remove everything up to last "/"
         symlink ($oldname, $newname);
    }
Of course, with Perl, "There's always more than one way to do it".
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论