Help on TCL Lists

Discussion in 'Perl Misc' started by RACHAK, Nov 27, 2003.

  1. RACHAK

    RACHAK Guest

    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
     
    RACHAK, Nov 27, 2003
    #1
    1. Advertising

  2. On 26 Nov 2003 16:48:41 -0800, (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.
     
    William Herrera, Nov 27, 2003
    #2
    1. Advertising

  3. 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 |
    | | the man who is alive." -- Cervantes |
    +--------------------------------+---------------------------------------+
     
    Gerald Lester, Nov 27, 2003
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. JustSomeGuy

    Sorting lists of lists...

    JustSomeGuy, Jun 17, 2004, in forum: C++
    Replies:
    0
    Views:
    335
    JustSomeGuy
    Jun 17, 2004
  2. Jon Slaughter

    lists of lists

    Jon Slaughter, Dec 13, 2004, in forum: C++
    Replies:
    4
    Views:
    436
    Buster
    Dec 13, 2004
  3. =?UTF-8?B?w4FuZ2VsIEd1dGnDqXJyZXogUm9kcsOtZ3Vleg==

    List of lists of lists of lists...

    =?UTF-8?B?w4FuZ2VsIEd1dGnDqXJyZXogUm9kcsOtZ3Vleg==, May 8, 2006, in forum: Python
    Replies:
    5
    Views:
    427
    =?UTF-8?B?w4FuZ2VsIEd1dGnDqXJyZXogUm9kcsOtZ3Vleg==
    May 15, 2006
  4. Chris Weisiger

    Help with sorting lists of lists

    Chris Weisiger, Oct 14, 2004, in forum: Perl Misc
    Replies:
    7
    Views:
    137
    Tad McClellan
    Oct 14, 2004
  5. Mumia W.

    Inline::Tcl vs. Inline::Tcl

    Mumia W., Aug 23, 2006, in forum: Perl Misc
    Replies:
    0
    Views:
    156
    Mumia W.
    Aug 23, 2006
Loading...

Share This Page