#!/usr/pkg/bin/perl -w use strict; foreach (@ARGV) { open TXT, '<', $_ or print STDERR "Error: couldn't open $_ for reading: $!\n" and next; s/\.txt$/.html/ or $_ .= '.html'; open HTML, '>', $_ or print STDERR "Error: couldn't open $_ for writing: $!\n" and next; select HTML; print '
';
 while () {
  1 while s/\t+/' ' x (length($&)*8 - length($`)%8)/e;
  pos() = 0; # just making sure
  # The following regular expressions were taken from Jef Poskanzer's
  # texttohtml program ().
  for (;;) {
   m!\G((?:https?|ftp|gopher)://[^>)}\],\s]+)!gci && do {
    print "$1"; next;
   };
   m!\G(www\.[[:alnum:].\-]+\.[[:alpha:]]{2,5}(?:/[^>)}\],\s]*)?)!gci && do {
    print "$1"; next;
   };
   m!\G((mailto:)?([\w+.\-]+@[[:alnum:]+.\-]+))!gci && do {
    print "$1"; next;
   };
   m!\G(telnet:[[:alnum:]+.:@\-]+)!gci && do {
    print "$1"; next;
   }
   m!\G!gc && do {print '>'; next; };
   m!\G&!gc && do {print '&'; next; };
   m!\G([^[:ascii:]])!gc && do {print '&#', ord $1, ';'; next; };
   m!\G(.)!gc && do {print $1; next; };
   last;
  }
 }
 print '
'; }