Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
 
This week, we're updating our course layouts and descriptions. Presentation and materials always gently change over time, but just occasionally there's a need to make a step change to clear out some of the old and roll in the new. That's now happening - but over a long and complex site it's not instant and you'll see sections of the site changing up to and including 19th September.

See also [here] for status update
 
reg parsing

Posted by kannarv1 (kannarv1), 16 February 2007
Hi in my program o/p looks like

CsD-1299 07-02-10 13:03:34 happy-77 M00009800002005750/011200
      1       |   state        |   down         |    up    
--------------|----------------|----------------|----------------

 abc            DOWNLOAD            YES               NO          

i need to get the up  value

my program look slike


proc hdlrSync { } {
       global RBUFFER
       global  SYNC UP DOWN  NO YES UNKNOWN

       set foundPattern 0
       foreach line [split $RBUFFER "\n"] {
                set line "$line\n"
                if [string match "*-----*" $line] {
                       set foundPattern  1
                       continue
                }
                if { $foundPattern ==1 } {
                       set _val [lindex $line 3]
                       
                        if [ regexp "NO.*" $_val] {
                               return $NO
                       }
                       if [ regexp "YES.*" $_val] {
                               return $YES
                       }
                       return $UNKNOWN
                }        
       
       return $UNKNOWN
}


I always get the value unknown coz after i match *-------* there is a new line  in the o/p .how do i match \n .I tried matching likeh this but dint work .

if [string match "\n" $line] {
                    continue
 }

how can i match the line ? Thanks for the help





Posted by admin (Graham Ellis), 16 February 2007
The split takes out the \n, so it's not there when you do

if [string match "\n" $line] {
     continue
 }

Try

if [string match "" $line] {
     continue
 }

instead

Posted by kannarv1 (kannarv1), 16 February 2007
nope it dint solve the problem .I still could not figure out the logical mistake here

proc hdlrSync { } {
  global RBUFFER
  global  SYNC UP DOWN  NO YES UNKNOWN

  set foundPattern 0
  foreach line [split $RBUFFER "\n"] {
      set line "$line\n"
      if [string match "*-----*" $line] {
                  set foundPattern  1
                   continue
      }
      if [string match "" $line] {
               continue
      }
      if { $foundPattern ==1 } {
      set _val [lindex $line 3]
   
      if [ regexp "NO.*" $_val] {
               return $NO
     }
    if [ regexp "YES.*" $_val] {
                    return $YES
   }
    return $UNKNOWN
  }    
   
  return $UNKNOWN
}

Thanks for the help

Posted by admin (Graham Ellis), 17 February 2007
The logic is probably not the way I would have written it, but looks sound.  Have you tried printing out various intermediate stages ... seeing whether the foundPattern variable even gets set to 1, for example?

Posted by kannarv1 (kannarv1), 19 February 2007
thanks graham It matches *----*and foundpattern is set but the line does not match match ""  or "\n" .....so its still throwing the value is unknown since after the pattern  *----* there is a empty line

Posted by kannarv1 (kannarv1), 19 February 2007
thanks grham its working now .got one more question

how do i match match a space in tcl

Posted by admin (Graham Ellis), 21 February 2007
put a space between the pair of double quotes in the string match or literally include a space character within a regular expression.



This page is a thread posted to the opentalk forum at www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2014: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 899360 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho