home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / historic / v941.tgz / icon.v941src.tar / icon.v941src / ipl / progs / shortest.icn < prev    next >
Text File  |  2000-07-29  |  1KB  |  45 lines

  1. ############################################################################
  2. #
  3. #    File:     shortest.icn
  4. #
  5. #    Subject:  Program to write shortest line in a file
  6. #
  7. #    Author:   Ralph E. Griswold
  8. #
  9. #    Date:     November 25, 1992
  10. #
  11. ############################################################################
  12. #
  13. #   This file is in the public domain.
  14. #
  15. ############################################################################
  16. #
  17. #  This program writes the (last) shortest line in the input file.  If the
  18. #  command-line option  -# is given, the number of the shortest line is
  19. #  written first.
  20. #
  21. ############################################################################
  22.  
  23. procedure main(argl)
  24.    local shortest, min, count, countl, number, line
  25.  
  26.    if argl[1] == "-#" then number := 1
  27.  
  28.    shortest := read() | exit()
  29.    count := 1
  30.    min := *shortest
  31.  
  32.    every line := !&input do {
  33.       count +:= 1
  34.       if *line <= min then {
  35.          min := *line
  36.          shortest := line
  37.          countl := count
  38.          }
  39.       }
  40.  
  41.    if \number then write(countl)
  42.    write(shortest)
  43.  
  44. end
  45.