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

Re: PATCH: new parameter expansion type?



On Aug 30, 11:49am, Sven Wischnowsky wrote:
} Subject: PATCH: new parameter expansion type?
}
}   ${name^pattern^then^else}
} 
} Gives you the (substituted) `then' string if the expansion of `name'
} matches the `pattern' and otherwise it gives you the `else' string.

Isn't this just the same as

	${${${(M)name#pattern}:+then}:-else}

except of course that you have to be a little selective about whether
you use # or % to delimit the pattern?

I'm not particularly excited by the ^test^true^false syntax nor by the
trick of making "." magic in the true/false strings.  I vote against this
patch, in its current form at least.  Sorry, Sven.

} Ok, the `.' thingy is just because I couldn't think of a better
} character/syntax (suggestions?) and this isn't as powerful as I would
} like it because `then' and `else' can't expand to arrays. Maybe we
} could make `${(A)foo^?^$arr1^$arr2}' do that (and maybe we could do
} the same for `${(A)foo:-$arr}'.

This is essentially the same problem as ${(A)foo:=string} where it would
be nice to be able to have "string" be interpreted as an array.  I pointed
out the parsing problem with this back at that time.  It would be nice to
have a solution; Andrej suggested ${(A)foo:=(val1 val2 ...)} but it will
require a change to the parser to make that work.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com



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