cltk编程及应用简介.ppt
《cltk编程及应用简介.ppt》由会员分享,可在线阅读,更多相关《cltk编程及应用简介.ppt(53页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、Allrightsreserved2010,AlcatelShanghaiBellProductTest-Shanghai/April2010Tcl and the Tk ToolkitChenTaoApril,2010Allrightsreserved2010,AlcatelShanghaiBellProductTestShanghai/April2010OutlinesTcl/TkAroundUsTcl/TkOverviewBasicTclSyntaxIntroductionforTkIntroductionforExpectHomebrewTestAutomationFrameworkT
2、heSURofTAOProjectResourcesAllrightsreserved2010,AlcatelShanghaiBellProductTestShanghai/April2010Tcl/TkAroundUsAllrightsreserved2010,AlcatelShanghaiBellProductTestShanghai/April2010FromWorkPlaceInWCSInITE/8610nUsingExpecttocommunicatewithWCS:send CLI commands and get response.InCiscoIOSRouterenableRo
3、uter#tclshRouter(tcl)#puts$tcl_version8.3TestAutomationforTelecommunicationandNetworkEquipmentsAllrightsreserved2010,AlcatelShanghaiBellProductTestShanghai/April2010ToOurDailyLifeItseasytodesignhandyprogramsbasedonTcltofulfilldifferenttasksnAfishscreensaveprogramnAe-pianonAPaintingpadAllrightsreserv
4、ed2010,AlcatelShanghaiBellProductTestShanghai/April2010Tcl/TkOverview-Say“tickle tee-kay”Allrightsreserved2010,AlcatelShanghaiBellProductTestShanghai/April2010WhatsTclTclstandsforToolCommandLanguagenJohOusterhout,UniversityofCalifornia.nFirstreleasewasin1989.Asimplescriptinglanguage:nCrossplatformsu
5、pport.Tclcanrunonmostpopularoperationsystemsuchasunix/linux,Windows,MacintoshandsoforthnScriptsareinterpretedatruntime.Whichmakesthedevelopmentcyclefasterthancompiledlanguages,nowaitingforlongcompilationsnThecapabilitytocallC/C+routinesnSimilartoothershelllanguagessuchasUNIXCshell,Perl,VB.“EasyEasy”
6、tostudynExcellenttextanalysiscompetenceAllrightsreserved2010,AlcatelShanghaiBellProductTestShanghai/April2010WhatsTcl(cont)Un-typedandastring-basedcommandlanguagenDatatypesarenotusedwhenvariablesaredefined.Youneedntspecifyavariableasinteger,floatorastring.nThebasicmechanismsareallrelatedtostringsand
7、stringsubstitutionsAllvariablesarestoredasstrings.automatictypeconversionincontextsetx10;#createavariable“x”andgiveavalue“10”toitsety20;#createavariable“y”andgiveavalue“20”toitsetzexpr$x+$y;#xplusyandsaveresultin“z”sety“Imastringnow.IndeedImalwaysstring:-)”puts“Expressionresultis:$z”;#printresultons
8、tandardoutputs“Ybecomesas:”$y”setaArray“JackboyMerrygirl”;#defineanarrayputs“Imanarray,butastringindeed:n$aArray”Allrightsreserved2010,AlcatelShanghaiBellProductTestShanghai/April2010WhatsTcl(cont)EasytoextendnTherearenumerousfreeextensionsbuiltontopofTcl/TkforspecificfunctionsavailableontheInternet
9、.Tclx:HandlingsignaleventsNet-Snmp:supportsnmpcommuninicationBWidget/IWidgetetc.:TkextensionsprovidesspecialandpowerfulwidgetsHttp&ncgi:forhttpserverprogrammingnItiseasytoaddnewTclprimitivesbywritingCproceduresTcl/TkisPureCOpen-Sourcecode,newTclcommandscanbeimplementedbyspecificextensionsprogrammedi
10、nC,fairlyeasywithoutchangingTclcore.TotallyFree!Allrightsreserved2010,AlcatelShanghaiBellProductTestShanghai/April2010WhatsTkTknATcl-basedtoolkitforprogramminggraphicaluserinterfacesnQuickandeasytobuildpowerfuluserinterfaces.nPortable,onecopyofscriptcanworkunchangedonUNIX,Windows,andtheMacintosh.All
11、rightsreserved2010,AlcatelShanghaiBellProductTestShanghai/April2010WhatsExpectExpectnATcl-basedToolkitforAutomatingInteractiveProgramsTheprograminteractivelypromptandexpectusertoenterkeystrokesinresponsenAdefaultcommandinsomeoperationsystemsnTheresalsoanExpectextensionfortclwhichcanalsobeloadedtotcl
12、shellAllrightsreserved2010,AlcatelShanghaiBellProductTestShanghai/April2010TclnotsogoodnewsInterpretedlanguagesrunslowerandusemoreprocessingtimeoroverheadWithoutacomplier,syntaxerrorscantbefounduntilthescriptisexecutedUn-typedlanguagesdonotallowforthemostefficienttranslationofcodeAllrightsreserved20
13、10,AlcatelShanghaiBellProductTestShanghai/April2010BasicTclSyntaxAllrightsreserved2010,AlcatelShanghaiBellProductTestShanghai/April2010TclCommandsFormatATclscriptconsistsofoneormorecommandsnCommandsareseparatedbynewlinesorsemi-colonsAscriptwithtwocommandsseparatedbyanewlinecharacter:seta24setb25Abov
14、escriptcouldbewrittenonasinglelineusingasemi-colonseparator:seta24;setb25BasicallyeachcommandconsistsofoneormorewordsnFirstwordisthenameofacommandnAdditionalwordsareargumentstothatcommandnWordsareseparatedbyspacesandtabsvar1var2Allrightsreserved2010,AlcatelShanghaiBellProductTestShanghai/April2010Va
15、riableNeedntdeclarethetypeofvariable,automaticconversionincontextset x“10.99”;#this is a stringputs“expr int($x)”;#output would be 10NeedtobedeclaredandassignedavaluebeforeuseVariablenameiscase-sensitiveAssignmentexpression:setTousevalueofavariable,puta“$”aheadofitas$nIfyouwanttoappendextracharacter
16、stoavariable,usebracesaroundvariablenameas:set x“Hello ”puts“$xJack!”;#This is wrong,it would treat xJack as variable nameputs“$xJack!”;#This is right!Differentscopesshouldsharevariablevaluesbyspecificmethods.nnamespacenprocedureTouseglobaltovisitglobalvariablesnchildreninterpreterAllrightsreserved2
17、010,AlcatelShanghaiBellProductTestShanghai/April2010CommentsCommentissetinashellway,leadingbya“#”seta(“john”)boy;#Setvalueofelement“john”ofarray“a”as“boy”#Orwecandoasarrayseta“johnboy”;#Ifyoulik,youcancommentusingmulti-linesBecarefulwhenaddcommentstoa“switch”expressionswitchvar“go”tohandlego#Ifitdoe
18、snotsupportfollowingvalue,commentitlater:=Wrong!“pause.Allrightsreserved2010,AlcatelShanghaiBellProductTestShanghai/April2010StandardOutput&InputI/Ooperationforstandardinputandoutput,normallytheterminalinfrontofus.Printoutonterminal:puts“abcdefgNoThanks.”Formatthestringbyusing“format”commandnSimilar
19、asCset str format“%-2d%20s%9d”,193 is not equal to 0133;#octal number“193 is not equal to 91”Getinput:puts-nonewline“Your name please:”gets stdin sNameAllrightsreserved2010,AlcatelShanghaiBellProductTestShanghai/April2010MathandLogicalExpressionexprexprexpr1+2;setx10;sety20;expr$x+$y=30exprabs(-10)=
20、10expr10*rand()=9.06197207004855;#resultisdouble,0value5;#inrangeof07incrsetx1incrx=2incrx3=5incrx-2=3logic“and”“or”.Allrightsreserved2010,AlcatelShanghaiBellProductTestShanghai/April2010Control:BranchandLoopIf.elseif.else.ifBoolean expressionifxxxelseifxxxelseif elseForsetsum0;forseti0;sety10$i450W
21、hilewhilegets$fdline=0Switchswitch-exact$xyz“0”;?break?;“1”?default?Foreach(refertooperationoflist)Allrightsreserved2010,AlcatelShanghaiBellProductTestShanghai/April2010List,Array&Operation“list”representalistofstringnCommandsforlistlist,lindex,lrange,lappend,lreplacesplit,joinArrayissimilarasthe“as
22、sociate”arrayorhashdatainperlorphp.%set lst1“Jack boy blue Merry girl red”;#or%set lst2 list Red White Yellow Blue%foreach x$lstputs“$xn”%foreachx y z$lst1 puts student name:$x,a$y,who likes$zstudent name:Jack,a boy,who likes bluestudent name:Merry,a girl,who likes redputs lindex$lst2 2=Whiteputs li
23、ndex$lst2 0=Red%array setaArrlistJackboyMerrygirl%parrayaArraArr(Jack)=boyaArr(Merry)=girl%array getaArrJack boy Merry girl%array namesaArrJack Merry%array sizeaArr2%foreach x y array get aArr puts Name:$x,a$yName:Jack,a boyName:Merry,a girlAllrightsreserved2010,AlcatelShanghaiBellProductTestShangha
24、i/April2010String&Operationappendformatsubststringcommandnstringcomparenstringmatchnstringequal(addedin8.4)nstringrangenstringtolower/touppernstringtrimstringcomparation:nif$str1=$str2putsequalnstringcomparingcommandssuchas“stringmatch”stringclasscheck:nstringisifstringisinteger10putsokAllrightsrese
25、rved2010,AlcatelShanghaiBellProductTestShanghai/April2010ProcandReturnProcedureintclsimilarasfunctioninC,perl,php,unixshelletc.nprocarg1arg2.argsprocbodynreturnstringproccalc1opa“opb10”returnexpr$opa+$opbcalc123=5calc12=12proccalc2args;#Varyargumentlistsetopalindex$args0setopblindex$args1returnexpr$
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- cltk 编程 应用 简介
限制150内