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))
tcl string works

Posted by xramm (xramm), 8 February 2008
I am using expect , and want to add +1 to an IP number which is being read from file. In unix shell script I did it by using cut command , I wonder it is possible to do in Tcl

IP number format like 192.168.xxx.yy
and want to make form as 192.168.xxx.yy+1

any advise ?

Posted by admin (Graham Ellis), 9 February 2008
I would split the incoming IP address up with regexp, add one to the last number with expr, and rebuild.

Posted by xramm (xramm), 9 February 2008
thanks for your advise

which regexp option (switches) will be suitable for accomplish this task ?
-line ?

Posted by admin (Graham Ellis), 10 February 2008
I don't think you'll need any options at all!

Posted by xramm (xramm), 10 February 2008
as an sample; my ip address is 172.26.234.13 and want to make it 172.26.234.14
ip1="172.26.234.13"


would you please give me an example to start ?

Posted by admin (Graham Ellis), 10 February 2008
If you have a look at the other threads on this board, you'll find that we're here to help with learning rather than to provide a free "write it for me" service ... so I am rather reluctant to do the whole job for you.  However

Code:
set writeit 172.26.234.13
regexp {(\d+)\.(\d+)\.(\d+)\.(\d+)} $writeit all in a long line
incr line
set forme "$in.$a.$long.$line"
puts "$writeit $forme"


gave this result

Code:
dolphin:~ graham$ tclsh rrr
172.26.234.13 172.26.234.14
dolphin:~


Posted by xramm (xramm), 11 February 2008
we're here to help with learning rather than to provide a free "write it for me" service ...

->> of course , I am aware of this, I do not want you have wrong ideas about me. I asked because I am very new to Tcl, I am familiar with unix shell programming, I am able to write code in unix shell easily like my question but Tcl totally different and I cannot find adequate information yet.

Thanks for your help.

Posted by xramm (xramm), 11 February 2008
... we're here to help with learning rather than to provide a free "write it for me" service ...

->> of course , I am aware of this, I do not want you have wrong ideas about me. I asked because I am very new to Tcl, I am familiar with unix shell programming, I am able to write code in unix shell easily like my question but Tcl totally different and I cannot find adequate information yet.

Thanks for your help.

Posted by xramm (xramm), 11 February 2008
... we're here to help with learning rather than to provide a free "write it for me" service ...

->> of course , I am aware of this, I do not want you have wrong ideas about me. I asked because I am very new to Tcl, I am familiar with unix shell programming, I am able to write code in unix shell easily like my question but Tcl totally different and I cannot find adequate information yet.

Thanks for your help.

Posted by xramm (xramm), 11 February 2008
<#>... we're here to help with learning rather than to provide a free "write it for me" service ...</#>

->> of course , I am aware of this, I do not want you have wrong ideas about me. I appreciate this policy..
I asked because I am very new to Tcl, I am familiar with unix shell programming, I am able to write code in unix shell easily like my question but Tcl totally different and I cannot find adequate information yet.

Thanks for your help.

Posted by xramm (xramm), 11 February 2008
I could not make regexp worked for split IPs up.
My solution is:

#split IP address up
set ilk [ lindex [ split $site '\.' ] 0 ]
set iki [ lindex [ split $site '\.' ] 1 ]
set uc [ lindex [ split $site '\.' ] 2 ]
set son [ lindex [ split $site '\.' ] 3 ]
incr son

#setup for host
set ip3 "$ilk.$iki.$uc.$son"



Posted by admin (Graham Ellis), 11 February 2008
Yes, that works .... although I do find myself thinking if I see code repeated "surely there's an easier way".

Yes, I understand completely that you're new to Tcl and indeed we provide this board to help.   But where the question starts moving towards complete chunks of code, there are better / easier way such as books and courses which provide a far more effective route than a forum.



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