开发者

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".

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜