procmail
[Top] [All Lists]

Re: character substitution in $VARIABLE

2003-11-07 10:22:12
At 10:21 2003-11-07 -0500, Jake Di Toro wrote:

Asked I might have said the same thing... but:

 >ls -l `which sed` `which tr`
-rwxr-xr-x    1 root     root        21132 Jul  4  2001 /bin/sed*
-rwxr-xr-x    1 root     root        24056 Jul 12 09:54 /usr/bin/tr*

But again, these are your tools... unless you want to write a quicke
perl script, but that's even more overhead.

That may be debugging symbols still tacked onto the binaries. Addiditonally, it's possible that one binary is linked to shared libraries, and the other is statically linked.

Consistently on the hosts I checked (about half a dozen, running different versions of *nix), sed was roughly twice the size of tr. A couple of examples:

FreeBSD 4.4:
-r-xr-xr-x  1 root  wheel  21448 Sep 18  2001 /usr/bin/sed*
-r-xr-xr-x  1 root  wheel   9532 Sep 18  2001 /usr/bin/tr*

FreeBSD 4.9:
-r-xr-xr-x  1 root  wheel  23940 Nov  5 02:40 /usr/bin/sed
-r-xr-xr-x  1 root  wheel  11984 Nov  5 02:41 /usr/bin/tr


Since tr doesn't perform regexp operations, I would fully expect it to parse much quicker, but the difference is going to be negligible on something so trivial. If you were processing a large file, it'd be a different matter.

BTW, 'which' should be able to process multiple arguments in one invocation.

It is trivial to write a special purpose C program to translate the dots to dashes, taking the string on the commandline:

--- (snip)
# dotdash.c     simple program to transform dots in a command-line passed
#               string into dashes, with the result dumped to STDOUT.

#include <stdio.h>
#include <string.h>

int main( int argc, char * argv[])
{
        char *p;

        # prog expects only one argument (plus argv[0])
        if ( argc != 2 )
        {
                return( -1 );
        }

        # positional translation of the string, so it should be safe
        # to perform it right in the argv[] array.  Saves us the link
        # overhead of a strcpy.
        while ( p = strchr( argv[1], '.' ) )
        {
                *p = '-' ;
        };

        fputs( argv[1], stdout );
        return( 0 );
}

--- (snip)

to compile:

        cc -O3 -o dotdash dotdash.c
        strip dotdash

to use:

LISTNAME=`dotdash $LISTNAME`

---
 Sean B. Straw / Professional Software Engineering

 Procmail disclaimer: <http://www.professional.org/procmail/disclaimer.html>
 Please DO NOT carbon me on list replies.  I'll get my copy from the list.


_______________________________________________
procmail mailing list
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail

<Prev in Thread] Current Thread [Next in Thread>