----- Original Message ----- From: ""gaochong"" <zjgaoch...@gmail.com>
Newsgroups: perl.beginners
To: <beginners@perl.org>
Sent: Tuesday, November 17, 2009 6:41 AM
Subject: mkdir in the mounted partition,please help me,thanks


#!/usr/bin/perl -w



#Auther:gaochong



use strict;



my @list = (3 .. 9);

my @FA=("FA00000001".."FA00002000");

sub mk_fa {

       my ($f) = @_;

       foreach my $p (@list) {

               mkdir "/data$p/NRU/$f",0755 or warn "mkdir /data$p/NRU/$f
err:$!";

Hello gaochong,

The mkdir() function will not create any new directories in the 'path' to the last new directory

mkdir "/data$p/NRU/$f",0755
                     ^^           ^^

The 'data$p' directory must be created before the '$f' directory.

mkdir "/data$p" or warn "mkdir /data$p;

Then, you can say:
mkdir "/data$p/NRU/$f",0755 or warn "mkdir /data$p/NRU/$f

As to a better way, here is another way (without reconstructing the @list array).

#!/usr/bin/perl
use strict;
use warnings;
use File::Path; # uses 'mkpath' to make new included dirs in a path

my ($i, @p) = (-1, 3 .. 9);

foreach my $f ("FA00000001".."FA00002000") {
my $p = $p[++$i % @p];
#mkpath(["/data$p/NRU/$f"], 0, 0755) unless -e "/data$p/NRU/$f";
#symlink "/data$p/NRU/$f","/usr/local/Titan/NRU/$f"
# or warn"symlink /data$p/NRU/$f err:$!";
print "/data$p/NRU/$f\n";
}

This example uses the 'mkpath()' function which *will* construct the entire path (unlike the mkdir() function). mkpath() is included in the base perl 5.8 distribution, so it may be available to you.

Chris

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to