Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: aliases not getting expanded inside functions?



Bart Schaefer (schaefer@xxxxxxxxxxxxxxxx) wrote on 11 January 2003 18:40:
 >	: ${(P)1::=$2}
 >	eval $1='$2'
 >	typeset -g $1=$2

Nice!

 >Rather than:
 >
 >    while read dataline
 >    do
 >      fields=( "${(@s:;:)dataline}" )	# Answers your other question

Doesn't work for me:

    fields=( "${(@s:;:)dataline}" )
    print LINE=$dataline
    for ((i=1; i <= 16; i++)) { print "fields[$i]=\"$fields[i]\"" }

gives

LINHA="BD CCE";"CCE";"210";"0";"1-254";33;7;1;;;;;;;"permit";
fields[1]=""BD CCE""
fields[2]=""CCE""
fields[3]=""210""
fields[4]=""0""
fields[5]=""1-254""
fields[6]="33"
fields[7]="7"
fields[8]="1"
fields[9]=""permit""         <--- wrong
fields[10]=""
fields[11]=""
fields[12]=""
fields[13]=""
fields[14]=""
fields[15]=""                <--- permit should be here
fields[16]=""

 >      rate=$fields[1] capital=$fields[2] etc.
 >      # manipulate $rate $capital and so on ...
 >    done
 >
 >You can simply do:
 >
 >    while IFS=';' read rate capital etc.
 >    do
 >      # manipulate $rate $capital and so on ...
 >    done

Yes, I didn't do it because I had hope to one day do a block move
via arrays. Also, reading to a parameter first makes it easier to do
some pre-processing like quote removal, otherwise I have to do it
field by field after reading.

 >If you're unwilling to use $fields[capital] everywhere -- that is, if
 >you insist on being able to write $capital in some cases -- then there
 >is no solution I can suggest.  However, if it's OK to write e.g.
 >
 >    fields[capital]=$((fields[capital]+fields[interest]))

This makes the program more cumbersome to write and read because all
variables become quite long-named...



Messages sorted by: Reverse Date, Date, Thread, Author