Friday, 15 March 2013

perl - Force a folder to be made if one doesn't exist -



perl - Force a folder to be made if one doesn't exist -

how forcefulness folder made in code below, line 31, when 1 doesn't exist already. i've tried mkdir command can't work. tried >> instead of one. line i'm talking about: "open $fh, '>', "ask/parsed/html/$"

utilize lib '/users/lialin/perl5/lib/perl5'; utilize strict; utilize warnings; utilize feature 'say'; utilize file::slurp 'slurp'; # makes easy read files. utilize mojo; utilize mojo::useragent; utilize uri; #my $html_file = "ask/agilent_technologies_ask.html"; # take file directory #my $html_file = shift @argv; # take file command lin $calls_dir = "ask/"; opendir(my $search_dir, $calls_dir) or die "$!\n"; @html_files = grep /\.html$/i, readdir $search_dir; closedir $search_dir; #print "got ", scalar @files, " files\n"; #my %seen = (); foreach $html_files (@html_files) { %seen = (); $current_file = $calls_dir . $html_files; open $file, '<', $current_file or die "$html_files: $!\n"; $dom = mojo::dom->new(scalar slurp $calls_dir .$html_files); print $calls_dir .$html_files ; #for $csshref ($dom->find('a[href]')->attr('href')->each) { #for $link ($dom->find('a[href]')->attr('href')->each) { # print $1; #say $1 #if $link->attr('href') =~ m{^https?://(.+?)/index\.php}s; open $fh, '>', "ask/parsed/html/${html_files}.result.txt" or die $!; $csshref ($dom->find('a[href]')->attr('href')->each) { $cssurl = uri->new($csshref)->abs($calls_dir .$html_files); #open $fh, '>', "ask/${html_files}.result.txt" or die $!; $fh->print("$html_files\n"); $fh->print("$cssurl\n"); #$fh->print("\t"."$_\n"); #print "$cssurl\n"; #print $file."\t"."$_\n"; }}

i suggest using file::path, make_path().

you can write recursive function mkdir, seems me not worth trouble, module worked fine me.

perl file directory writing

No comments:

Post a Comment