Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Help on TCL Lists

Reply
Thread Tools

Help on TCL Lists

 
 
RACHAK
Guest
Posts: n/a
 
      11-27-2003
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
 
Reply With Quote
 
 
 
 
William Herrera
Guest
Posts: n/a
 
      11-27-2003
On 26 Nov 2003 16:48:41 -0800, http://www.velocityreviews.com/forums/(E-Mail Removed) (RACHAK) wrote:

>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.


---
Use the domain skylightview (dot) com for the reply address instead.
 
Reply With Quote
 
 
 
 
Gerald Lester
Guest
Posts: n/a
 
      11-27-2003
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


RACHAK wrote:
> 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


--
+--------------------------------+---------------------------------------+
| Gerald W. Lester | "The man who fights for his ideals is |
| (E-Mail Removed) | the man who is alive." -- Cervantes |
+--------------------------------+---------------------------------------+

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to build a loadable tcl dll with visual studio (microsoft C compiler)?[crosspost in comp.lang.tcl and comp.lang.c++] Michael Reichenbach C++ 5 02-08-2010 02:38 PM
Inline::Tcl vs. Inline::Tcl Mumia W. Perl Misc 0 08-23-2006 04:09 PM
List of lists of lists of lists... =?UTF-8?B?w4FuZ2VsIEd1dGnDqXJyZXogUm9kcsOtZ3Vleg==?= Python 5 05-15-2006 11:47 AM
Help with sorting lists of lists Chris Weisiger Perl Misc 7 10-14-2004 01:42 PM
Help with using TCL/JACL with BSF in JSP for CFMX 6.1/JRUN env Phil Powell Java 0 09-17-2003 02:53 PM



Advertisments