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 2021 - online Python 3 training - see ((here)).

Our plans were to retire in summer 2020 and see the world, but Coronavirus has lead us into a lot of lockdown programming in Python 3 and PHP 7.
We can now offer tailored online training - small groups, real tutors - works really well for groups of 4 to 14 delegates. Anywhere in the world; course language English.

Please ask about private 'maintenance' training for Python 2, Tcl, Perl, PHP, Lua, etc.
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., 2022: 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