Help on TCL Lists

R

RACHAK

InPut File
============
BUCKET|Drawing Type|Assembly|Stage|1|GTTBRG001_ASM|
BUCKET|Drawing Type|Machining|Stage|2|GTTBRG002|
LOCKING BUCKET|Drawing Type|Machining|Stage|3|GTTBRG003|
NOZZLE TURBINE|Drawing Type|Assembly|Stage|3|GTTBSG003_ASM|
NOZZLE TURBINE|Drawing Type|Machining|Stage|3|GTTBSG003|
STUB SHAFT COMPRESSOR|Drawing
Type|Machining|Stage|0|LOCATION|FWD|GTCPRO000|
COMPRESSOR|Drawing Type|Machining|Stage|1|LOCATION|FWD|SUB
LOCATION|FWD1|GTTCRX001|


The above data is in a input file, will be dynamic, can change over a
period and more Key Value pairs can be added

File Description:
First Column is Header Info for each record Example:
COMPRESSOR
Last Column is the Final Value that has to be returned. EXAMPLE:
GTTCRX001

Remaining Columns are represented/used as Key Value Pairs.
Expample:
Drawing Type, Machining
Stage,1
LOCATION,FWD
SUB LOCATION, FDW1
We can add any number of Key Value pairs for each record.


Help:
Can some one provide me a solution for doing this task.

Read the File & For each record ( combination of First & Last Column
: get all the Key Value Pairs )
Check this key value pairs exists in a list "INLIST" and if all the
Key Value Pairs are found Return the last Column


INLIST: ( Is not a file but output of another Process )
{COMPRESSOR-> Drawing Type->Machining->Linear
Assembly->BKT->Stage->1->LOCATION->FWD1->SUB
LOCATION->FWD1->CAP->Assembly }

Example:

Drawing Type->Machining ( Key Value Match found for Column1=COMPRESSOR
when compared between INLIST and input File )
+
Stage->1 ( Key Value Match for Column1=COMPRESSOR when compared
between INLIST and input File )
+
LOCATION->FWD1 ( Key Value Match for Column1=COMPRESSOR when compared
between INLIST and input File )
+
SUB LOCATION->FWD1 ( Key Value Match for Column1=COMPRESSOR when
compared between INLIST and input File )

Since all the 4 Key Value Pairs exists in the "INLIST"

Retrun Last Column from InputFile "GTTCRX001"


Thanks in Advance
RACHAK
 
W

William Herrera

InPut File
============
BUCKET|Drawing Type|Assembly|Stage|1|GTTBRG001_ASM|
BUCKET|Drawing Type|Machining|Stage|2|GTTBRG002|
LOCKING BUCKET|Drawing Type|Machining|Stage|3|GTTBRG003|
NOZZLE TURBINE|Drawing Type|Assembly|Stage|3|GTTBSG003_ASM|
NOZZLE TURBINE|Drawing Type|Machining|Stage|3|GTTBSG003|
STUB SHAFT COMPRESSOR|Drawing
Type|Machining|Stage|0|LOCATION|FWD|GTCPRO000|
COMPRESSOR|Drawing Type|Machining|Stage|1|LOCATION|FWD|SUB
LOCATION|FWD1|GTTCRX001|


The above data is in a input file, will be dynamic, can change over a
period and more Key Value pairs can be added

File Description:
First Column is Header Info for each record Example:
COMPRESSOR
Last Column is the Final Value that has to be returned. EXAMPLE:
GTTCRX001

Remaining Columns are represented/used as Key Value Pairs.
Expample:
Drawing Type, Machining
Stage,1
LOCATION,FWD
SUB LOCATION, FDW1
We can add any number of Key Value pairs for each record.


Help:
Can some one provide me a solution for doing this task.

Read the File & For each record ( combination of First & Last Column
: get all the Key Value Pairs )
Check this key value pairs exists in a list "INLIST" and if all the
Key Value Pairs are found Return the last Column


INLIST: ( Is not a file but output of another Process )
{COMPRESSOR-> Drawing Type->Machining->Linear
Assembly->BKT->Stage->1->LOCATION->FWD1->SUB
LOCATION->FWD1->CAP->Assembly }

Example:

Drawing Type->Machining ( Key Value Match found for Column1=COMPRESSOR
when compared between INLIST and input File )
+
Stage->1 ( Key Value Match for Column1=COMPRESSOR when compared
between INLIST and input File )
+
LOCATION->FWD1 ( Key Value Match for Column1=COMPRESSOR when compared
between INLIST and input File )
+
SUB LOCATION->FWD1 ( Key Value Match for Column1=COMPRESSOR when
compared between INLIST and input File )

Since all the 4 Key Value Pairs exists in the "INLIST"

Retrun Last Column from InputFile "GTTCRX001"

Why do you need to do this?

anyway, you probably need to set up the lines as arrays of hashrefs and then
compare, like

my @lines = <DATA>;
my @data;
foreach(@lines) {
chomp;
s/\|$//;
my @a = split /\|/;
my $head = shift @a or warn 'Bad data line: $_';
my $tail = pop @a or warn 'Bad data line: $_';
my %h = @a;
$h{'Header Info'} = $head;
$h{'Final Value Returned'} = $tail;
push @data, \%h;
}

my @listlines = '{COMPRESSOR->Drawing Type->Machining->Linear
Assembly->BKT->Stage->1->LOCATION->FWD1->SUBLOCATION->FWD1->CAP->Assembly}';
my @list;
foreach(@listlines) {
s/^\{|\}$//g;
my @a = split /\-\>/;
my $head = shift @a or warn 'Bad data line: $_';
my %h = @a;
$h{'Header Info'} = $head;
push @list, \%h;
}

....now do a compare of the two arrays of hashrefs.
 
G

Gerald Lester

If I understand your problem correctly, this should do:

#!/bin/sh
# the next line restarts using tclsh \
exec tclsh "$0" "$@"

set INLIST [exec ProcessThatGeneratesInList]
set ifd [open {InPut File} r]
while {[gets $ifd line] != -1} {
set list [split line {|}]
set keyList {}
foreach {key value} [lrange $list 1 end-1] {
lappend keyList $key
}
set test [join $keyList {->}]
if {[string equal $test $INLIST]} then {
puts stdout [lindex $list end]
}
}
close $ifd
exit
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top