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

Re: aliases not getting expanded inside functions?



On Jan 13,  3:59pm, Carlos Carvalho wrote:
}
}  >      fields=( "${(@s:;:)dataline}" )	# Answers your other question
} 
} Doesn't work for me:

Hrm.  I was sure I'd tried it, but on your input I get the same result
you do.  Well, there's always:

    IFS=';' eval 'fields=( $=dataline )'

However, it occurs to me that with dataline='...;";";...' -- that is, a
quoted semicolon in the input data -- there's no quick solution that's
going to do exactly what you need.

}  >    while IFS=';' read rate capital etc.
} 
} 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.

[...]

}  >    fields[capital]=$((fields[capital]+fields[interest]))
} 
} This makes the program more cumbersome to write and read because all
} variables become quite long-named...

So don't name the array "fields", name it "f" or some such.  Three extra
characters (e.g. $f[capital] instead of $capital) for a whole lot less
complexity elsewhere.  And quote removal may be as easy as:

	f=( ${${(kv)f#\"}%\"} )

(Whether it's actually that easy depends on your input data, e.g., you
might also need to convert \" to ", but I think `read' will have done
that for you already.)



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