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

Re: foo=${(z)${(s:.:)SECONDS}} ; echo ${foo[1]}.${(r:2:)foo[2]}



On Thu 25.Oct.07 16:37, Atom Smasher wrote:
i want that number to be reported only to hundredths of a second (two decimal places). i could just say that there are 10 decimal places and i want to get rid of eight:
	print "${SECONDS/%????????/}"
	25867.46

but that would break if the number of digits after the decimal point changes. which leads me to:
	% foo=${(z)${(s:.:)SECONDS}} ; echo ${foo[1]}.${(r:2:)foo[2]}
	25969.87

which works fine, but i'm wondering if there's a more graceful way to do that without an intermediate variable (foo, in this case).

Use backreferences, e.g.:

print ${SECONDS//(#b)(*.??)*/${match[1]}}

--
redondos

Attachment: signature.asc
Description: Digital signature



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