home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.perl
- Path: sparky!uunet!gatech!psuvax1!flee
- From: flee@cs.psu.edu (Felix Lee)
- Subject: Perl meets shell
- Message-ID: <Brs2rD.Fz1@cs.psu.edu>
- Sender: news@cs.psu.edu (Usenet)
- Nntp-Posting-Host: dictionopolis.cs.psu.edu
- Date: Wed, 22 Jul 1992 07:45:05 GMT
- Lines: 51
-
- I've been slowly collecting a pile of Perl routines that I want to use
- in both shell scripts and Perl scripts. But it's rather awkward to
- arrange for this to happen.
-
- Presumably, in Perl, you would do something like
- require 'fqdn.pl';
- $y = &fqdn($x);
-
- And in shell you would do
- y=`fqdn $x`
- or
- cat list | fqdn
-
- Supporting the shell usage requires writing a wrapper that applies the
- routine to @ARGV or <STDIN>. The awkward part is this same wrapper
- has to be written for every little routine in the library.
-
- Instead, what I have right now are two Perl programs, "perl-apply" and
- "perl-map", that can be used like so:
- y=`perl-apply fqdn $x`
- cat list | perl-map fqdn
- perl-map fqdn `cat list`
-
- "perl-apply proc args" locates proc, loads it, calls proc with all the
- args, and prints the result.
-
- "perl-map proc args" locates proc, loads it, calls proc on each arg
- (or on each line of STDIN), and prints each result on a separate line.
-
- This still isn't ideal. The shell usage is somewhat messy.
-
- It would be nice if the same file could be used for both purposes.
- This requires a way for the file to know whether it's being run as a
- script, or loaded with "require" (or "do").
-
- Here's one approach. If you put something like
- #!/usr/bin/wrapper
- at the top of the file, this will get ignored. Unfortunately, the
- wrapper has to be a binary executable.
-
- Perhaps the wrapper could be Perl itself, with a new flag.
- Something like:
- #!/usr/bin/perl -Emain
- The "-Emain" means that the procedure "main" should be called after
- the file is loaded, after all the immediate statements are executed,
- before exiting.
-
- Does this seem reasonable? It still seems messy.
-
- (Why doesn't Unix fit together smoothly on all levels? sigh.)
- --
-