Results 1 to 2 of 2

Thread: Arrays

  1. #1
    Join Date
    Oct 2002
    Posts
    39

    Unanswered: Arrays

    Hello,

    I have two arrays

    arrayA[x]
    arrayB[y]

    In arrayA I have 20 procedures
    In arrayB I have 2 procedures that need to be excluded from arrayA

    How can I remove these from arrayA, the data stored in arrayB will be the array number (e.g. x) that needs to be excluded from my processes...

    Any ideas would be great.. I'm doing this in korn shell...

  2. #2
    Join Date
    Oct 2002
    Posts
    39
    Tek-tips.com helped provide this solution.. FYI:

    set -- ${arrayA[@]} # set positional parameters to elements of arrayA

    integer subb=0

    for i in $@ # for each parameter (ie $1 $2 $3 ...)
    do
    subb=0
    while : #endless loop
    do
    # if there is a match, we want to drop this element
    [[ $i = ${arrayB[subb]} ]] &&
    break #jump out of THIS loop
    (( subb += 1 ))
    #if we've tested all elements of arrayB, then we have no match
    [[ $subb -ge ${#arrayB[*]} ]] &&
    {
    #so we build a new variable containing all elements of arrayA that we want to keep.
    NewString=" $NewString $i"
    break
    }
    done
    done
    set -A arrayA $NewString # recreate arrayA


    ${#arrayB[*]} evaluates to number of array elements
    ${arrayA[@]} evaluates to all array elements
    ${arrayA[*]} evaluates to all array elements
    ${arrayB[subb]} evaluates to the array element indexed by $subb

    Once you have created an array, you cannot "remove" any elements, or insert any new ones.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •