#! /usr/local/bin/perl

# reads in a list of network addresses from ARGV[0], and mails the
# message in ARGV[1] to all these addresses 

   #  open the file specified in the first command-line argument,
   #     which will be the list of network addresses; if this fails, 
   #     then print the error message and exit
   open(LIST,@ARGV[0]) || die "Can't open $ARGV[0]\n";

   #  do the same for the file containing the message to be mailed
   open(MSG,@ARGV[1]) || die "Can't open $ARGV[1]\n";

   #  while there are still lines left to read from the list file do
   while (<LIST>)  {
      # $_ is the line read from LIST; we will form a Unix command
      #    from it
      # remove the last character (newline character) from $_
      chop;
      # concatenate ('.' operation) the string "mail" with $_,
      #    and assign the result (e.g. "mail matloff@cs.ucdavis.edu")
      #    to $cmd
      $cmd = "mail " . $_; 
      # do some more concatenatation
      $tmp = " < " . "$ARGV[1]";
      $cmd = $cmd . $tmp;
      # now our Unix command looks like, say,
      #    mail matloff@cs.ucdavis.edu < ImportantMessage
      # now execute the command, by giving it to Unix 
      system($cmd);
   }


