G'day dobster936,

Welcome to the Monastery.

One potential problem is lines like

$fr="$dirtoget$f"; ... $fw="$dirwrite$f";

Do $fr and $fw evaluate to /some/dirname/somefilename or /some/dirnamesomefilename? Add print statements to find out. See the builtin File::Spec module to "portably perform operations on file names".

Another problem is performing I/O without checking whether it worked. See open for examples of how to do this. Alternatively, use the autodie pragma and let Perl do it for you.

And yet another issue is assuming everything, except "." and "..", is a normal file:

unless ( ($f eq ".") || ($f eq "..") ) {

See the file test operators. Given that unless block has no closing brace, you could just change those two lines to:

next unless -f $f;

Global (package) variables have all sorts of problems. Choose lexical variables and control their scope yourself. See "Private Variables via my()" for further discussion.

Finally, as others have already indicated, use the strict and warnings pragmata. There's really no value in spending time tracking down problems in your code when Perl will do it for you.

-- Ken


In reply to Re: Perl Script in Windows Works, but not in Unix by kcott
in thread 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.