Home
History
Comparisons
Examples
Documentation
  Help File
Download
News
Wish List
Soapbox

Project:
  Forums
  Tracker
  CVS

Hosted by:
  Sourceforge
  VA Linux

Author

Hawk / Ftwalk Comparisons: Perl

Perl is a free software program which is primarily intended for writing scripts for various UNIX system administration tasks. It is richly featured, widely distributed, extensible, and relatively mature.

Perl is approximately equivalent to Ftwalk scripts with a MAIN block (i.e., that do not generate input events). There is very little that either language can do that the other cannot do, so the principal differentiation between them is language style, ease of use, and learning curve.

As a means of comparison, the following sample of Perl code comes from an article in Byte magazine [Feb. 1996, p. 137]. This code finds numeric Internet addresses in its standard input file, looks up and replaces the address with its hostname, and write the edited line to the standard output file. This code is used to make Web log files more readable:

    $AF_INET = 2;
    $ADDRESS_PATTERN = "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+";
    while (<>) {
        /$ADDRESS_PATTERN/;
        @addr = split(/\./,$&);
        $addr = pack(' C4', @addr[0], @addr[1], @addr[2], @addr[3]);
        ($name,$aliases,$type,$len,@addrs) = gethostbyaddr($addr,$AF_INET);
        if ($name ne "") {
            s/$ADDRESS_PATTERN/$name/;
        }
        print $_;
    }
The equivalent Ftwalk code would be:

    AddressPattern = //[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+//
    while (S = gets) {
        if (S ~ AddressPattern) {
            IpAddr = S.substr(RSTART, RLENGTH)
            Addr = gethostbyaddr(IpAddr)
            if (Addr.name)
                S.sub(AddressPattern, Addr.name)
        }
        print(S)
    }