This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Major newbie help with IF statements

Old posts that have not been replied to for several years.
Locked
o
oioifatty
Voice
Posts: 7
Joined: Sun May 08, 2005 7:53 pm

Major newbie help with IF statements

Post by oioifatty »

Hi, i've got a smal tcl code that reads the contents of a file for devices, eth0, eth1 etc...
the devs file contains all of the items in the list, but it only returns the last item that matches in the dev file, i know its something to do with the IF's, but i just can't get my head arounfd the correct layout. could any suggest the correct layout?

Code: Select all

set devices "/proc/net/dev"
set file [ open $devices r ]
set data [read -nonewline $file]   
close $file
set lines [split $data "\n"]
foreach line $lines {
   if [string match "*lo:*" $line] {
      set lo lo
      } else { set lo ""}
    if [string match -noc "*eth0:*" $line] {
      set eth0 eth0
      } else { set eth0 ""}
   if [string match -noc "*eth1:*" $line] {
      set eth1 eth1
      } else { set eth1 ""}
   if [string match -noc "*ppp0:*" $line] {
      set ppp0 ppp0
      } else { set ppp0 ""}
   if [string match -noc "*ppp1:*" $line] {
      set ppp1 ppp1
      } else { set ppp1 ""}
}
"if it's in a book, it's gotta be true"
User avatar
Alchera
Revered One
Posts: 3344
Joined: Mon Aug 11, 2003 12:42 pm
Location: Ballarat Victoria, Australia
Contact:

Post by Alchera »

Click here for full information regarding "if" statements.
Add [SOLVED] to the thread title if your issue has been.
Search | FAQ | RTM
g
greenbear
Owner
Posts: 733
Joined: Mon Sep 24, 2001 8:00 pm
Location: Norway

Post by greenbear »

you're overwriting your var every time there's a match, use append/lappend to append (doh) it to your var.
o
oioifatty
Voice
Posts: 7
Joined: Sun May 08, 2005 7:53 pm

doh

Post by oioifatty »

Thank you for your posts, the help is very appreciated.
and thank you gb, thats the third or forth time you've helped me.
"if it's in a book, it's gotta be true"
Locked