procmail
[Top] [All Lists]

Re: A tip (was: Reversing text?)

2002-05-15 01:47:33
On Tue, May 14, 2002 at 01:29:18PM +0300, Udi Mottelo wrote:

awk 'BEGIN{NF=split(O,T,".");for(i=NF;i;i--)N=N"/"T[i];print N;exit}' O=$MATCH

Udi,

   That's nifty!

   One hint, though. As is, the script depends on which awk are you using.
Standard awks should not recognise command-line variable assignments in the
BEGIN action. Gawk does, but only if the assignment is prefixed with -v.

man gawk >>>
       -v var=val
       --assign var=val
         Assign  the  value  val to the variable var, before execution of the
         program   begins.   Such variable values  are  available to the BEGIN
         block of an AWK program.

   ...

POSIX COMPATIBILITY

   ...

       The book indicates that command line  variable  assignment
       happens when  awk  would otherwise open the argument as a
       file, which is after the BEGIN block  is  executed.   How-
       ever,  in earlier implementations, when such an assignment
       appeared before any file names, the assignment would  hap-
       pen  before the BEGIN block was run.  Applications came to
       depend on this "feature."  When awk was changed   to  match
       its  documentation,  the -v option for assigning variables
       before program execution was added to accommodate applica-
       tions  that depended upon the old behavior.  (This feature
       was agreed upon by both the Bell Laboratories and the  GNU
       developers.)
<<<

Regards,
Erik

_______________________________________________
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>