Listing cross cases within lists in TCL


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Listing cross cases within lists in TCL
# 1  
Old 12-07-2012
Listing cross cases within lists in TCL

Hello everyone, I am new here forgive me if I omit something,

I have a problem which I can't seem to solve using TCL so I am posting it here.
Here it is :

I retrieve a UNKNOWN number of lists from an XML file. Let's skip the part where I retrieve these lists and say for example that you have these lists hereunder.

Code:
set list1[list toto titi tutu]
set list2[list pvt1 pvt2 pvt3]
set list3[list I12  I13]

I wanted to store every cross cases that I can find i.e.
Code:
case 1 : toto pvt1 I12
case 2 : toto pvt1 I13
case 3 : toto pvt2 I12
etc....

I thought about a recursive call but I can't manage to get an algorythm right like passing the number of cases or the lists or making directly lists of lists maybe someone can help me?

Thank you, again if something is missing please tell me.
Regards

Noob

Last edited by Scrutinizer; 12-07-2012 at 07:55 AM.. Reason: code tags
# 2  
Old 12-07-2012
Logically, you are talking about a join, where you decompose your lists into lines, tuples, database rows, like 'list1 toto' and 'case3 I12', one for one. They you can join the file/table/relation of lists with the file/table/relation of cases using the 'join' tool or other join oriented tactics. You have a many-to-many thing going on in cases, but you could use associative arrays to store list ids by item id and look list id up by case item ids.

When the structure of the data is wrong, the problem is hard. Fix the structure, don't try to solve two problems at once. It is simple if all item ids are in one column/attribute.
# 3  
Old 12-07-2012
Hi.

I looked at this as a situation in enumeration/combination. Judging by the sample output, I would address it with nested loops -- 3 in this case.

Perhaps I don't have a sufficient grasp of the problem ... cheers, drl
# 4  
Old 12-07-2012
Wel, in some languages you can have lists of lists, so you can say:
for every list of list1 of lists
get every item of the list and for it
get every list of list2 of lists
get every item of that list
compare item of list of list1 with item of list of list2
but you are decomposing the lists over and over, so for efficiency, you can decompose both once, sort them and do the sort-optimized cartesian join in 'join' or you can put one decomposed list of lists into one associative array and look up every line of the other list of lists.

It is important to see the disorder of having peer data elements in two dimensions, across and down the page. Disorder generates more code and less speed.
# 5  
Old 12-07-2012
Hi.

This seems to produce sample output:
Code:
#!/usr/bin/env tclsh

# @(#) tcl2     Demonstrate nested loops and lists.

set version [ info tclversion ]
set message " Hello, world from tclsh ($version), $auto_path"
puts ""
puts stdout $message
puts ""

set list1 [ list toto titi tutu ]
set list2 [ list pvt1 pvt2 pvt3 ]
set list3 [ list I12  I13 ]

foreach i  $list1 {
  foreach j $list2 {
    foreach k $list3 {
      puts "$i $j $k"
    }
  }
}

puts ""

exit 0

producing:
Code:
% ./tcl2

 Hello, world from tclsh (8.4), /usr/share/tcltk/tcl8.4 /usr/lib /usr/local/lib/tcltk /usr/local/share/tcltk /usr/lib/tcltk /usr/share/tcltk

toto pvt1 I12
toto pvt1 I13
toto pvt2 I12
toto pvt2 I13
toto pvt3 I12
toto pvt3 I13
titi pvt1 I12
titi pvt1 I13
titi pvt2 I12
titi pvt2 I13
titi pvt3 I12
titi pvt3 I13
tutu pvt1 I12
tutu pvt1 I13
tutu pvt2 I12
tutu pvt2 I13
tutu pvt3 I12
tutu pvt3 I13

Best wishes ... cheers, drl
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep strings for different cases

Hi All, Good morning I have a below code which is working & getting expected output. the problem in this code is it is executing 3 if conditions, my requirement is suppose if first condition is success then it should print echo statement & exit from if condition else if the 1st if condition... (4 Replies)
Discussion started by: sam@sam
4 Replies

2. UNIX for Dummies Questions & Answers

[Solved] How to remove listing of current user cmd from ps -ef listing?

Hi All, Could you please help to resolve my following issues: Problem Description: Suppose my user name is "MI90". i.e. $USER = MI90 when i run below command, i get all the processes running on the system containing name MQ. ps -ef | grep MQ But sometimes it lists... (8 Replies)
Discussion started by: KDMishra
8 Replies

3. Shell Programming and Scripting

Extract match cases

hi guys i have a file like this which is contain more than 3000 records i want to extract emails have Creation Date: : Wed, 14 Aug 2009 and their POP3 Last Login Date and WebMail Last Login Date is Thu, 01 Jan 1970 how can i could do that for example in this sample i need... (13 Replies)
Discussion started by: mhs
13 Replies

4. Shell Programming and Scripting

Recursive Lists in Tcl

Hi, I am new to tcl programming, i want to know how to write a procedure for list operations taking the user input from command line and outputs the the index of each element in the list. Eg: input list is : { 1 2 {ab cde} {acf t12 l34} 3 5{43 {try 5 }} } something like this. output should... (6 Replies)
Discussion started by: mail2leo
6 Replies

5. Shell Programming and Scripting

Shell Script to Create non-duplicate lists from two lists

File_A contains Strings: a b c d File_B contains Strings: a c z Need to have script written in either sh or ksh. Derive resultant files (File_New_A and File_New_B) from lists File_A and File_B where string elements in File_New_A and File_New_B are listed below. Resultant... (7 Replies)
Discussion started by: mlv_99
7 Replies

6. UNIX for Dummies Questions & Answers

Search for a string with different cases

Hi Guys, I am using the following command in a script. cat $sql_file_path"/"${sql_file_list} | grep "ABCDE" but it returns only exactly matching lines (ABCDE) how can i modify this single line so it will return if it finds a matching string with any case. eg: Abcde, abCDe, abcdeE,... (4 Replies)
Discussion started by: mwrg
4 Replies

7. UNIX for Advanced & Expert Users

test cases

in my organisation the unix server is migrated.the ip of the server changed and the hardware.i need to test that i am aving the same file structure and data which is created under my user id.and the utilities like sqlplus,ftp are working or not.i am talking abt the general user perspective who... (0 Replies)
Discussion started by: dr46014
0 Replies

8. Solaris

2 cases !!! plz advise

i've installed solaris 10 on E 3500 server .. 1. i cant install patch cluster on it , cause when i extract the file , i gives me an OUT file .. i dont know what to do with it . 2. i want to know which files to edit so i can use Exceed Client Software for X Terminal .. its working fine with... (9 Replies)
Discussion started by: mduweik
9 Replies

9. UNIX for Dummies Questions & Answers

Recursive directory listing without listing files

Does any one know how to get a recursive directory listing in long format (showing owner, group, permission etc) without listing the files contained in the directories. The following command also shows the files but I only want to see the directories. ls -lrtR * (4 Replies)
Discussion started by: psingh
4 Replies
Login or Register to Ask a Question