I have used the use::File::Found to traverse the directory and its sub directories but i am getting the following error for this program . Cannot open 'folder-name': permission denied at monks.pl at line 42 . Please anyone help me to resolve how to access all the files in the directory.
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper; $Data::Dumper::Useqq = 1;
use File::Find;
find(\&wanted,'D:\coding\patientperclinic-withouthistory');
sub wanted
{
my $icd_path = 'D:\coding\icd-10-codes.txt';
my $in_path = <*>;
my $out_path = 'D:\coding\female1_corrected.txt';
open my $icd_fh, '<', $icd_path
or die "Cannot open '$icd_path': $!";
#print "Reading '$icd_path'\n";
my %lookup_icd;
while ( my $line = <$icd_fh> ) {
chomp $line;
my ( $lookup_code, $icd_code_and_text ) = split /\t/, $line;
# print Dumper $lookup_code, $icd_code_and_text;
if ( exists $lookup_icd{$lookup_code} ) {
warn "Replacing $lookup_code;"
. " was '$lookup_icd{$lookup_code}',"
. " now '$icd_code_and_text'\n";
}
$lookup_icd{$lookup_code} = $icd_code_and_text;
}
close $icd_fh;
#print Dumper \%lookup_icd;
#print "Reading '$in_path'\n";
#print "Writing '$out_path'\n";
open my $in_fh, '<', $in_path
or die "Cannot open '$in_path': $!";
open my $out_fh, '>', $out_path
or die "Cannot open '$out_path': $!";
while ( my $line = <$in_fh> ) {
chomp $line;
my @cols = split / /, $line;
for my $possible_icd (@cols) {
my $replacement_icd = $lookup_icd{$possible_icd};
if ($replacement_icd) {
$possible_icd = $replacement_icd;
}
}
print {$out_fh} join( ' ', @cols ), "\n";
}
close $in_fh;
close $out_fh
or warn "Cannot close 'out_path': $!\nSome data may not have been
+written.";
unlink $in_path
or die "Could not delete '$in_path': $!";
use File::Copy;
move( $out_path, $in_path )
or die "Could not move file '$out_path' to '$in_path': $!";
}
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.