[Appendix A] A.13 Chapter 14, Process Management
Author: Randal L. Schwartz, Erik Olson & Tom Christiansen
Date: 1999-07-02T01:37:41Z

#

| Appendix A Exercise Answers |

## A.13 Chapter 14, Process Management

1. Here's one way to do it:

       my ($src, $trg) = @ARGV;
       die "$src isn't a directory" unless -d $src;
       die "$trg isn't a directory" unless -d $trg;
       `xcopy /s /e $src $trg`;

   We check to make sure both arguments are really directories, then we invoke xcopy to do the dirty work. We could have also used:

       system("xcopy /s /e $src $trg");

2. Here's one way to do it:

       @hosts = `net view`;
       foreach (@hosts) {
         next unless m#\\\\#;
         chop;
         s/^(\S+).*/$1/;
         push @sorted, $_;
       }
       print join("\n", sort @sorted);

   We run the command net view and capture the output as a list of lines. We then go through each line looking for hostnames (they start with \\), chop off newlines and comments, and add the matches to another list. We then sort the second list and print it.

A.12 Chapter 13, File and Directory Manipulation |  | A.14 Chapter 15, Other Data Transformation