mkdir in a loop?
Anonymous Monk
created: 2006-04-05 05:30:42
hi monks,

I have a list of filenames, and for each one I want to create a directory with that filename. However, I keep getting directories with '?' on the end that don't actually seem to exist. Can anyone advise? Thanks!

open (FILE, "all_controls.txt") or die "can't open file $!";

my @file=;

foreach my $file (@file)   {
        mkdir "$file";
}


Re: mkdir in a loop?
created: 2006-04-05 05:31:57

chomp(my @file = );
Re: mkdir in a loop?
created: 2006-04-05 05:46:17
open (FILE, "all_controls.txt") or die "can't open file $!";

my @file=;
chomp @file;
foreach my $file (@file)   {
        mkdir "$file";
}

Regards,
Murugesan Kandasamy
use perl for(;;);

Re: mkdir in a loop?
created: 2006-04-05 10:54:09
I noticed the "?" mark too. Check the "all_control.txt" file to see if it has any extra formatting characters. Then the following should work fine. #!/usr/bin/perl use strict; my $file = "all_controls.txt"; open(FILE, "<$file") || die "Unable to open $file: $!\n"; my @file_contents = ; foreach (@file_contents) { chomp; $_ =~ /^(.*?)\..*?$/; # remove filename extension after '.' mkdir ($1, 0755) || die "Unable to create directory: $!\n"; print "Created directory: $1\n" if (! $@); } # end
Re: mkdir in a loop?
created: 2006-04-05 11:01:13
Check "all_control.txt" for any extra formatting characters.

#!/usr/bin/perl

use strict;

my $file = "all_controls.txt";

open(FILE, "<$file") || die "Unable to open $file: $!\n";
my @file_contents = ;
foreach (@file_contents) {
 chomp;
 $_ =~ /^(.*?)\..*?$/; # remove filename extension
 mkdir ($1, 0755) || die "Unable to create directory: $!\n";
 print "Created directory: $1\n" if (! $@);
}

# end

perlmonks.org content © perlmonks.org and ambrus, Anonymous Monk, murugu, wand3ringscript3r

prlmnks.org © 2006 edmund von der burg (eccles & toad)

v 0.03