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!


In reply to Perl Script in Windows Works, but not in Unix by dobster936

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.