Passing evaluator in as ARG. question / possible?

Homepage Clovertech Forums Read Only Archives Cloverleaf Cloverleaf Passing evaluator in as ARG. question / possible?

  • Creator
    Topic
  • #54434
    Mike Wilson
    Participant

    Folks.  I am trying to build a more dynamic tcl proc.  I want to do the following.  Is it possible?  

    I want to pass 4 values in as ARGS.  SEGMENT, FIELD, EVAL, CRITERIA

    they would like something like this: OBR, 4, ==, HELLO

    in my proc I have:

    if {$SEGMENT_$FIELD $EVAL $crit} {

                   echo “meets the IF: Remove it”

               lappend dispList “KILL $mh”

    I get this error: syntax error in expression “$SEGMENT_$FIELD $EVAL $crit”: extra tokens at end of expression

    It wont use the $EVAL as an actual operator / evaluator.  If I replace the variable with an actual == or >, etc it works as expected.  

    Thanks for any insight.

Viewing 7 reply threads
  • Author
    Replies
    • #81449
      Russ Ross
      Participant

      We have some procs that do what you speak of.

      I looked at the first TCL proc I could find that does what you want, so there might be other methods being used, but here is one way to do it.


      # I ran the following from hcitcl interactively as proof of concept
      # tailored to my understanding of your example

      set SEGMENT OBR
      set FIELD
      [code]
      # I ran the following from hcitcl interactively as proof of concept
      # tailored to my understanding of your example

      set SEGMENT OBR
      set FIELD

      Russ Ross
      RussRoss318@gmail.com

    • #81450
      Mike Wilson
      Participant

      just needed the curly braces around the 2 variables.  {}.  I thought I had tried that with no success.  This works great now.  Thanks.

    • #81451
      Russ Ross
      Participant

      Please post the TCL code snippet that you got to work to make the solution you went with more clear.

      Below is my interpretation of what you described as getting it to work, which must be an incorrect interpretation since this doesn’t work.

      Code:


      set seg_field ${SEGMENT}_${FIELD}
      if {{$seg_field} $EVAL {$crit}} {
         echo TRUE
      } else {
         echo FALSE
      }

      Here is another possible interpretation that also doesn’t work, so I need to see your working code snippet to come to the correct understanding of your solution.

      Code:


      set seg_field ${SEGMENT}_${FIELD}
      if {$seg_field {$EVAL} $crit} {
         echo TRUE
      } else {
         echo FALSE
      }

      Russ Ross
      RussRoss318@gmail.com

    • #81452
      Mike Wilson
      Participant

      Here it is:

      I haven’t tested this with every operator.  But the usuals work so far, >,<,==, etc.

      I can pass the 4 arguments and do whatever filtering is needed.  

      Code:

      if {[expr {$seg_fld_length} $oper {$crit}]} {
                     echo “meets the IF $crit: Remove it”
                 lappend dispList “KILL $mh”
                 } else {
      echo ” Does not meet IF: Keep it”
                     lappend dispList “CONTINUE $mh”
                 }

    • #81453
      Russ Ross
      Participant

      Thanks, now I understand the solution you implemented.

      Russ Ross
      RussRoss318@gmail.com

    • #81454

      Here’s another example of using NetConfig args.

      Code:

      # NetConfig Args Example 1: {PATTERN {trigger}}
      # NetConfig Args Example 2: {PATTERN {^PEPPP[VHNW][HN]$}}

      proc tps_fileset_dirparse_regex { args } {
         global HciConnName HciSiteDir
         set module “tps_fileset_dirparse_regex /$HciConnName”
         set debug 1
         set dispList {}
         keylget args MODE mode

         set uargs {}; keylget args ARGS uargs
         set pattern “”; keylget uargs PATTERN pattern
         if {$debug} {puts “DEBUG: $module: pattern: $pattern”}

         switch -exact — $mode {
             start {}

             run {
                 keylget args MSGID mh
                 set fileList [msgget $mh]

                 set outList {}

                 foreach fileName $fileList {
                     if {$debug} {puts “DEBUG: $module: fileName: $fileName”}
                     if {[regexp $pattern $fileName]} {
                         lappend outList $fileName
                     }
                 }

                 msgset $mh $outList
                 lappend dispList “CONTINUE $mh”
             }

             time {}
             shutdown {}
             default {}
         }

         return $dispList
      }

      -- Max Drown (Infor)

    • #81455
      Mike Wilson
      Participant

      Max Drown wrote:

      Here’s another example of using NetConfig args.

      # NetConfig Args Example 1: {PATTERN {trigger}}
      # NetConfig Args Example 2: {PATTERN {^PEPPP[VHNW][HN]$}}

      proc tps_fileset_dirparse_regex { args } {
      [code]# NetConfig Args Example 1: {PATTERN {trigger}}
      # NetConfig Args Example 2: {PATTERN {^PEPPP[VHNW][HN]$}}

      proc tps_fileset_dirparse_regex { args } {

    • #81456
      Robert Kersemakers
      Participant

      Mike: this is a dirparse proc. The message $mh contains a list of files that were found during the scan of the specified directory. No need to pass netconfig args.

      This way you can filter which files you want to eventually read into the engine. The CONTINUEd message is a list of filenames that you want to process.

      Zuyderland Medisch Centrum; Heerlen/Sittard; The Netherlands

Viewing 7 reply threads
  • The forum ‘Cloverleaf’ is closed to new topics and replies.

Forum Statistics

Registered Users
5,053
Forums
28
Topics
9,236
Replies
34,175
Topic Tags
273