On Fri, Aug 3, 2012 at 1:07 AM, Roland Mainz <roland.ma...@nrubsig.org> wrote:
> Hi!
>
> ----
>
> It seems the [[ -v varname ]] operator is (again) broken for .sh.match
> in ast-ksh.2012-07-27:
> Example:
> -- snip --
> $ ksh -c 's="aaa bbb 333 ccc 555" ;
> s="${s//~(E)([[:alpha:]]+)|([[:digit:]]+)/NOP}" ; integer i=2 j=3 ; [[
> -v .sh.match[i][j] ]] && print fail'
> fail
> -- snip --
>
> The .sh.match array contains...
> -- snip --
> (
>         (
>                 [0]=aaa
>                 [1]=bbb
>                 [2]=333
>                 [3]=ccc
>                 [4]=555
>         )
>         (
>                 [0]=aaa
>                 [1]=bbb
>                 [3]=ccc
>         )
>         (
>                 [2]=333
>                 [4]=555
>         )
> )
> -- snip --
> ... which means .sh.match[2][3] is definately not set... but [[ -v
> .sh.match[2][3] ]] returns 'true'.
>
> <frustration>
> This is much fun since I tried to write the (or better: a ksh93
> version) DocBook2astgetopts parser tonight... but it turns out without
> being able to use .sh.match properly and check for "no match" with [[
> -v .sh.match[x][y] ]] there is no way to do it... ;-(
> </frustration>
>
> BTW: This must work, too (without producing differences in "diff"):
> -- snip --
>         # copy .sh.match to ar
>         integer i j
>         for (( i=0 ; i <= ${#.sh.match[@]} ; i++ )) ; do
>                 for (( j=0 ; j < ${#.sh.match[i][@]} ; j++ )) ; do

This should be...
-- snip --
for (( j=0 ; j < ${#.sh.match[0][@]} ; j++ ))
-- snip --
... since only .sh.match[0] has the full number of matches while
.sh.match[x] where x>0 are (likely) sparse (e.g. have holes in the
array).

>                         [[ -v .sh.match[i][j] ]] && 
> ar[i][j]="${.sh.match[i][j]}"
>                 done
>         done
>
>         diff -u <(print -v ar) <(print -v .sh.match)
> -- snip --

----

Bye,
Roland

-- 
  __ .  . __
 (o.\ \/ /.o) roland.ma...@nrubsig.org
  \__\/\/__/  MPEG specialist, C&&JAVA&&Sun&&Unix programmer
  /O /==\ O\  TEL +49 641 3992797
 (;O/ \/ \O;)
_______________________________________________
ast-developers mailing list
ast-developers@research.att.com
https://mailman.research.att.com/mailman/listinfo/ast-developers

Reply via email to