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
 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
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., 2024: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho