zsh-users
 help / color / mirror / code / Atom feed
* Writing element number into element, of array
@ 2017-03-06 15:07 Sebastian Gniazdowski
  2017-03-06 16:21 ` Daniel Shahaf
  0 siblings, 1 reply; 2+ messages in thread
From: Sebastian Gniazdowski @ 2017-03-06 15:07 UTC (permalink / raw)
  To: zsh-users

Hello,

# line=0
# arr=(  "a"  "ba"  "x-LINE-x"  "dcba"  )
# echo ${arr[@]//(#b)(((*)-LINE-(*))|(*))/$match[3]$(( mend[2] != -1 ?
++ line : ( ++line, 0 ) ))$match[4]$match[5]}

$mend[2] is: ((*)-LINE-(*))
$match[3] is: first (*)
$match[4] is: second (*)
$match[5] is: |(*)

result:

0a 0ba x3x 0dcba

So this is quite close, "3" is written onto -LINE-, but I cannot get rid
of the "0". How can this be done?

-- 
  Sebastian Gniazdowski
  psprint3@fastmail.com


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Writing element number into element, of array
  2017-03-06 15:07 Writing element number into element, of array Sebastian Gniazdowski
@ 2017-03-06 16:21 ` Daniel Shahaf
  0 siblings, 0 replies; 2+ messages in thread
From: Daniel Shahaf @ 2017-03-06 16:21 UTC (permalink / raw)
  To: Sebastian Gniazdowski; +Cc: zsh-users

Sebastian Gniazdowski wrote on Mon, Mar 06, 2017 at 07:07:38 -0800:
> # echo ${arr[@]//(#b)(((*)-LINE-(*))|(*))/$match[3]$(( mend[2] != -1 ?  ++ line : ( ++line, 0 ) ))$match[4]$match[5]}

You could probably slap a ${foo:/0/} around the $((…)) (see
${name:/pattern/repl} in zshexpn(1)), but personally, I wouldn't write
it as a one-liner in the first place, for readability.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-03-06 16:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-06 15:07 Writing element number into element, of array Sebastian Gniazdowski
2017-03-06 16:21 ` Daniel Shahaf

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).