dobster936 has asked for the wisdom of the Perl Monks concerning the following question:
Hi, I'm trying to run a perl script that is meant to extract a certain section from numerous text documents. The only thing the script requires of me is to input the read and write directories. In Windows it worked like a charm, though took several minutes to run on a relatively small batch (150) of text files. Later I will be automating this process on a cluster, and need to have it working in a Unix environment. When I do the same process I did on my Windows box on my Mac or on the cluster, perl instantaneously feeds me back the command prompt. On Windows, when I'd mess up I'd get an error message. Something like "No matches". For the time being I have set all permissions to 777 on the directories and files I am using (including the script). I've also ran a simple hello world script and received an output. I even tried using the dos2unix command on the text file to no avail. Below is the beginning of my script I am using:
#!/usr/bin/perl # Script to extract "item 7" from a 10-K report. # This will write the "good" part of the file to stdout, and will writ +e # a "schema string" on a single line to stderr. $dirtoget="E:\######"; $dirwrite="E:\#####"; opendir(IMD, $dirtoget) || die("Cannot open directory"); @thefiles= readdir(IMD); closedir(IMD); foreach $f (@thefiles) { unless ( ($f eq ".") || ($f eq "..") ) { $fr="$dirtoget$f"; open(FILEREAD, "< $fr"); $f=~s/.txt/.mda/g; $fw="$dirwrite$f"; #print $f1; open(FILEWRITE, "> $fw"); $x=""; while($line = <FILEREAD>) { $x .= $line; } # read the whole file into +one string close FILEREAD;
And yes, I am using forward slashes when switching to Unix directories. I've tried everything from single-quotes to starting with the root (~). I've also tried changing the shebang to env perl to no effect.
Also, I got it to the point where the code is running, but it is outputting: # This will write the "good" part of the: No such file or directory It would seem in the comment on line 5, it is trying to analyze "file" even thought it is commented out.
Update: turns out it was the end of the lines on the script. For some reason I forgot I received the text as an MS Word file (god only knows) and had to convert to txt from MS Word. When I used dos2unix command it got rid of all my line spacing all together for some odd reason. I had to reopen to original docx, save it as a text file and specify to end lines with lf. Thanks for all the time you took helping me today!
|
|---|