home *** CD-ROM | disk | FTP | other *** search
/ ftp.cse.unsw.edu.au / 2014.06.ftp.cse.unsw.edu.au.tar / ftp.cse.unsw.edu.au / pub / doc / languages / perl / nutshell / ch2 / reproach < prev    next >
Encoding:
Text File  |  1992-10-18  |  496 b   |  28 lines

  1. #!/usr/bin/perl
  2.  
  3. $_ = <STDIN>;
  4.  
  5. if (!/camels (\d+)/) {
  6.     print STDERR "Incorrect format--please try again!\n";
  7.     $errors++;
  8. }
  9. if ($1 <= 0) {
  10.     print STDERR "Incorrect format--please try again!\n";
  11.     $errors++;
  12. }
  13. if (/pigs/) {
  14.     print STDERR "Incorrect format--please try again!\n";
  15.     $errors++;
  16. }
  17.  
  18. # Alternate approach
  19.  
  20. &reproach if !/camels (\d+)/;
  21. &reproach if $1 <= 0;
  22. &reproach if /pigs/;
  23.  
  24. sub reproach {
  25.     print STDERR "Incorrect format--please try again!\n";
  26.     $errors++;
  27. }
  28.