comparing multiple list lengths 
Author Message
 comparing multiple list lengths

I'm comparing list_length_1 with list_length_2, then outputting a fault
message if mismatch.
I then compare list_length_1 with list_length_3, then outputting a
fault message,
and then compare list_length_1 with list_length_4, then outputting a
fault message.

e.g.

if {$list_length1 != $list_length2} {
  puts "Error in lists, unix list not same length as PC_ID list"
  puts ""
  puts "press Enter to exit"
  gets stdin garbage
  exit
  }

which i then repeat for lists 3 & 4.  I cant seem to get the OR
function to work, I've tried all sorts of combinations, all to no avail
so far!  I only need one error message to say all 4 lists are not equal
length.

TIA, Kev P.



Wed, 04 Jun 2008 00:01:48 GMT  
 comparing multiple list lengths

Quote:

> if {$list_length1 != $list_length2} {
>   puts "Error in lists, unix list not same length as PC_ID list"
>   puts ""
>   puts "press Enter to exit"
>   gets stdin garbage
>   exit
>   }

> which i then repeat for lists 3 & 4.  I cant seem to get the OR
> function to work, I've tried all sorts of combinations, all to no avail
> so far!  I only need one error message to say all 4 lists are not equal
> length.

if {$ll1 != $ll2 || $ll1 != $ll3 || $ll1 != $ll4} {
   # error stuff
   exit

Quote:
}

hth

--

phone +41 (0)44 247 79 79 | fax +41 (0)44 247 70 75
Netcetera AG | 8040 Zrich | Switzerland | http://netcetera.ch



Wed, 04 Jun 2008 00:15:38 GMT  
 comparing multiple list lengths

Quote:

> I'm comparing list_length_1 with list_length_2, then outputting a fault
> message if mismatch.
> I then compare list_length_1 with list_length_3, then outputting a
> fault message,
> and then compare list_length_1 with list_length_4, then outputting a
> fault message.

  if {$list_length1 != $list_length2 || \
      $list_length1 != $list_length3 || \
      $list_length1 != $list_length4
  } {
    puts "Error in lists, unix list not same length as PC_ID list"
    puts ""
    puts "press Enter to exit"
    gets stdin garbage
    exit
  }

Quote:
> which i then repeat for lists 3 & 4.  I cant seem to get the OR
> function to work, I've tried all sorts of combinations, all to no avail
> so far!  I only need one error message to say all 4 lists are not equal
> length.

Using OR will mean "if any list is not equal", if you really want to
mean "all lists are not equal" you must use AND:

  if {$list_length1 != $list_length2 && \
      $list_length1 != $list_length3 && \
      $list_length1 != $list_length4
  } {
    puts "Error in lists, unix list not same length as PC_ID list"
    puts ""
    puts "press Enter to exit"
    gets stdin garbage
    exit
  }

Actually, even this does not mean "all 4 lists are not equal", it
simply means "all lists are not equal to list_length1". If you really
want to do what you say you mean, you need:

  if {$list_length1 != $list_length2 && \
      $list_length1 != $list_length3 && \
      $list_length1 != $list_length4 && \
      $list_length2 != $list_length3 && \
      $list_length2 != $list_length4 && \
      $list_length3 != $list_length4
  } {
    puts "Error in lists, unix list not same length as PC_ID list"
    puts ""
    puts "press Enter to exit"
    gets stdin garbage
    exit
  }



Wed, 04 Jun 2008 08:06:22 GMT  
 comparing multiple list lengths

Quote:


> > I'm comparing list_length_1 with list_length_2, then outputting a fault
> > message if mismatch.
> > I then compare list_length_1 with list_length_3, then outputting a
> > fault message,
> > and then compare list_length_1 with list_length_4, then outputting a
> > fault message.
> <snip>
> Actually, even this does not mean "all 4 lists are not equal", it
> simply means "all lists are not equal to list_length1". If you really
> want to do what you say you mean, you need:

>   if {$list_length1 != $list_length2 && \
>       $list_length1 != $list_length3 && \
>       $list_length1 != $list_length4 && \
>       $list_length2 != $list_length3 && \
>       $list_length2 != $list_length4 && \
>       $list_length3 != $list_length4
>   } {
>     puts "Error in lists, unix list not same length as PC_ID list"
>     puts ""
>     puts "press Enter to exit"
>     gets stdin garbage
>     exit
>   }

Looking at your error message I realised you don't actually mean "all 4
lists are not equal" since if even a single list_length pair is equal
the if statement would be true. What you probably meant to say is "any
of the list is not equal" in which case if even a single list_length
pair is not equal the if statement would be false. Correct? If so:

   if {$list_length1 != $list_length2 || \
       $list_length1 != $list_length3 || \
       $list_length1 != $list_length4
   } {
     puts "Error in lists, unix list not same length as PC_ID list"
     puts ""
     puts "press Enter to exit"
     gets stdin garbage
     exit
   }



Wed, 04 Jun 2008 08:12:08 GMT  
 comparing multiple list lengths
Thta's what I wanted, thanks.
I was grouping each of the required list compares inside curly
brackets,
and ORing these..............

if {ll1 != ll2} ||{ll1 != ll3} .........etc

A bit confused over my bracket groups, simple really!

Thanks again, Kev P.



Fri, 06 Jun 2008 00:46:57 GMT  
 comparing multiple list lengths

Quote:

> Thta's what I wanted, thanks.
> I was grouping each of the required list compares inside curly
> brackets,
> and ORing these..............

> if {ll1 != ll2} ||{ll1 != ll3} .........etc

> A bit confused over my bracket groups, simple really!

> Thanks again, Kev P.

It's possible that you're still confused over "bracket groups".  For one
thing, I think you're actually referring to braces {}, not brackets [].

The important point to understand is that braces just turn a sequence of
characters (which might include whitespace -- spaces, tabs, newlines,
etc.) into a single word, from the viewpoint of the parser.  The only
braces you should be using in your fragment of code are the ones
separately surrounding the condition and the action of the if command.

  if {condition} {action}

Braces are a lot like double quotes, except that they prevent the parser
from applying variable substitution before the word is used.



Fri, 06 Jun 2008 02:12:07 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Intersection of multiple lists/list of lists

2. comparing two arrays with same length

3. Comparing vectors of unspecified length

4. Multiple lsearch and multiple list delete

5. Compare multiple files using rexx in SPFPro

6. Fixed-length fields with multiple words: How?

7. length of shortest string in list

8. Type based on list length

9. How to compare infinite lists?

10. length of list in buttoncreate

11. length of list in buttoncreate

12. Variable-length argument list

 

 
Powered by phpBB® Forum Software