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("
    ", 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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset