Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^3: Failed to open file for write

by BrowserUk (Patriarch)
on Apr 12, 2016 at 23:32 UTC ( [id://1160277]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Failed to open file for write
in thread Failed to open file for write

Based on your OP code; I cannot see a problem that would cause that error; but you have modified your code and that error message is a typical catchall report that is manifest when perl is confused by a typo.

The fastest solution would be to post the modified code that is producing the error.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^4: Failed to open file for write
by wrkrbeee (Scribe) on Apr 12, 2016 at 23:35 UTC
    I apologize, as taking way too much of your time. Please know that I appreciate your help! Updated code appears below.
    #! /usr/bin/perl -w use strict; use warnings; use lib "c:/strawberry/perl/site/lib"; use open ':std', ':encoding(UTF-8)'; #Specify location of input files; my $files_dir = 'D:/research/audit fee models/filings/test'; #Specify location of output results; my $write_dir = 'D:/research/audit fee models/filings/filenames/filena +mes.txt' #Open the directory containing the input files you will loop through; opendir (my $dir_handle, $files_dir); #Set up a loop for the sequentially reading the input files; while (my $filename = readdir($dir_handle)) { next unless -f $files_dir.'/'.$filename; print "Procesing $filename\n"; #Open the next file in the directory; open my $fh_in, '<', $files_dir.'/'.$filename or die "failed to open '$filename' for read"; #Initialize file counter; my $count=0; #Establish a loop to read the open file line by line; while (my $line = <$fh_in>) { #begin WHILE loop; print $line; #Open the output file for saving the results; open my $fh_out, '>', $write_dir.'/'.$filename or die "failed to open '$filename' for write"; print $fh_out "$line\n"; #write results to file; ++$count; #update line counter; } #end of while loop for current line; print "$count lines read from $filename\n;" } #end of current file loop;
      I don't know if this helps, but...
      #Open the output file for saving the results; open my $fh_out, '>', $write_dir.'/'.$filename or die "failed to open '$filename' for write";
      #Open the output file for saving the results; open my $fh_out, '>', "$write_dir/$filename" or die "failed to open \'$filename\' for write $!";
        Super! I appreciate your insight!!

      You have a semicolon (;) missing on the end of line 11.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
      In the absence of evidence, opinion is indistinguishable from prejudice.
        Duhhh! Okay, I feel really stupid. I'm really sorry to bother you, and waste your time. I will endeavor to do better in the future. Thank you so much!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1160277]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2024-04-19 04:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found