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

Belaboring substitution syntax




Ignore this post unless you're the sort of person who loved grammar in school:

   cc=( "${cc[@]/#%^*$~zsh_case${filter}*}" )

... working fine, and approved by Stephane and Roman.  But, trying to 'feel' the rightness of it, I sorta get that '[@]' is saying: "process this array line by line" thus preserving array indexes.  I'm not sure about the quotes.  Quotes seem to mostly combine words into lines -- or should I say that they mostly combine what would be word splitting into bigger elements: array=( "this array" "has" "three elements" ) ... and sometimes the quotes seem to protect stuff from expansion or interpretation: " $ echo "Yar 'en ign'rint fool!" ".  In my case, leaving the quotes out doesn't *seem* to matter but I know it would bite me eventually.  When would it bite me?

And:  " /#%^ "  ... it seems to me this is belaboring something simple.  Do we not have an operator that says (in English): If string A is a substring of B, then return B, else return nothing.  No anchors, no negation.  Inventing '!!' as my operator (yes I know it won't work but just for discussion):

   cc=( "${cc[@]!!$~zsh_case${filter}}" )

One operator instead of four. Actually, in such a construction the anchors would say: ... furthermore the substring must start at the beginning of the element:

   cc=( "${cc[@]!!#$~zsh_case${filter}}" )

... or must end at the end of the element:

   cc=( "${cc[@]!!%$~zsh_case${filter}}" )

... This wouldn't be a fancy substitution so much as a truth test with nulling of 'false'.  Dunno, but it seems like a simple thing and one of the first things a shell might be able to do.  Instead what we seem to have is a powerful operator that must then be dumbed down.

Not important, but if anyone is interested.






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