// A small comparison of scripting languages: :-)

3.7.4 Example script
--------------------

The following code snippets aim to provide an idea of how scsh compares
with other common scripting languages. They all print a list of all the
executables available in the current PATH to the standard output
(improvements to these examples are welcome).

   - `sh'
          #!/bin/sh

          IFS=':'
          for d in $PATH; do
            for f in $d/*; do
              [ -x $f -a ! -d $f ] && echo $f
            done
          done

   - `perl'

          What is the sound of Perl? Is it not the sound of a wall that
          people have stopped banging their head against?
          - _Larry Wall_

          #!/usr/local/bin/perl

          for my $dir (split /:/, $ENV{PATH}) {
             opendir DIR, $dir or die "can't opendir $dir: $!";
             -x "$dir/$_" && !-d _ && print "$_\n" for readdir DIR;
             closedir DIR;
          }

   - `python'
          #!/usr/local/bin/python

          import os, string, stat
          for d in string.split(os.environ['PATH'], ':'):
             for f in os.listdir(d):
                mode = os.lstat(d + '/' + f)[stat.ST_MODE]
                if not stat.S_ISDIR(mode):
                   print f

   - `ruby'
          #!/usr/bin/ruby

          ENV["PATH"].split(/:/).each {|path|
            Dir.foreach(path) {|file|
              puts(file) if File.stat(File.join(path, file)).executable?
            }
          }

   - `scsh'
          #!/usr/local/bin/scsh -s
          !#

          (define (executables dir)
            (with-cwd dir
               (filter file-executable? (directory-files dir #t))))
          (define (writeln x) (display x) (newline))

          (for-each writeln
             (append-map executables ((infix-splitter ":") (getenv "PATH"))))
// End

Enjoy!

Wesley Parish

P.S.  Oh yes, I am tempted by scsh.  Lisp is such a nice language (lost in 
stupid parentheses! though ;), and I do know a little from fooling around 
with AutoCAD's AutoLisp ... ;)
-- 
Clinersterton beademung, with all of love - RIP James Blish
-----
Mau e ki, he aha te mea nui?
You ask, what is the most important thing?
Maku e ki, he tangata, he tangata, he tangata.
I reply, it is people, it is people, it is people.

Reply via email to