Looking more closely at this version of your code, I'm wondering...

If you were to use File::Spec (as suggested above), here's how the code would start out:

use strict; use warnings; use Cwd; use Getopt::Long; use File::Spec; # this will automatically load OS-appropriate functi +ons # ... [snip] ... # Get the current working directory my $home_dir = getcwd; # Change to the test directory chdir($testdir) or die "$0: chdir $testdir: $!"; # Set up test dirs if they do not exist for my $t ( qw/test test1/ ) { mkdir $t or die "mkdir ". File::Spec->catfile($testdir, $t) .": $! +\n"; } # Change to the test area chdir("test") or die "chdir test: $!\n"; # Directory Manipulation for my $dir ( 0 .. $num-1 ) { my $dirname = "directory$dir"; # Make the directory if (!-d $dirname ) { mkdir $dirname or die "mkdir ". File::Spec->catfile( $testdir, "test", $dirn +ame ) .": $!\n"; } #...
I hope that gets the general idea across. It looks like your script is simply meant to check that certain operations work as hoped for, and doesn't really accomplish anything other than testing, so I won't pursue it further.

I'll just emphasize that you should use perl built-in functions and core modules (e.g. File::Copy whenever they are available, rather than system calls to shell commands -- perl already provides a lot of OS-independence for you, and you'll have fewer problems and less code to write that way.

If you really must use system calls to run OS-dependent tools, modularize and/or group those things so that they hang together for each OS. Your code tests the OS type in five different places, and you shouldn't have to do that test more than once (or not at all, with proper use of existing modules).


In reply to Re^3: System call constantly dying by graff
in thread System call constantly dying by gokuraku

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.