[BNE-PM] The Perl one-liner

Anthony Thyssen anthony at cit.gu.edu.au
Thu Sep 19 20:26:31 CDT 2002


Derek Thomson on  wrote...
| Anthony Thyssen wrote:
| > A much simpler way of doing this is to use the shell quoting to
| > include your shell veriable into the perl code.  I do this all the time
| > in shell scripts.
| 
| > 
| >    ls | perl -ne "print if m'$pattern'"
| 
| I've got a simpler answer ... don't write shell scripts! Seriously, I 
| got sick of all the porting problems (each tool has different abilities, 
| restrictions and bugs on each platform), and the fact that shell is just 
| no good once you need even a simple list, let alone complex data structures.
| 
If the script is only running commands, eg has to run a lot of ssh
Or bascially consists of a command with lots of options and a couple of
minor calculations or checks,  then a shell script is still better.
It is this sort of situation that the above "substitute argument"
works very well.

If it is extremely simple (for example - auto background, or a command
with a specific set of arguments) I don't even bother with a shell
script, I use a csh (or a shell function) alias.

The only other time I avoided perl is when a script may run of systems
where perl may not be installed, expecially new ones still being
installed!!!   OR it has to be sourced by the command shell as it must
change the shells environment (EG: shell setup/modification).

But you are right for anything else, especially when dealling with data,
or file manipulation, or just has security concerns, perl is the go.

| Calling "ls" or "cp" or whatever from Perl just makes your code
| non-portable, and very slow ...  and forcing yourself not to do this
| is a good way to learn about the standard modules!
| 
Agree but ther are things that it is a lot easier to call a command for.
File system dumps are one good example.  That is when either no module
is available or you know the command line method, but don't need or what
to know the "proper" perl interface.


  Anthony Thyssen ( System Programmer )    http://www.sct.gu.edu.au/~anthony/
 -----------------------------------------------------------------------------
   "You must realize that the computer has it in for you.  The irrefutable
   proof of this is that the computer always does what you tell it to do."
 -----------------------------------------------------------------------------
     Anthony's Home is his Castle     http://www.sct.gu.edu.au/~anthony/



More information about the Brisbane-pm mailing list