¡¡¡¡×÷Ϊϵͳ³ÌÐòÔ±£¬ÄúÏ°¹ßÐÔµØʹÓÃÃüÁîÐнçÃæ¡£¿ÉÄÜÄúÒѲ»Á˽âÓÃÇáÁ¿¼¶Í¼ÐÎÓû§½çÃ棨graphical user interface£¬GUI£©À´°ü×°ÏÖÓеŦÄÜÊǶàôµØÈÝÒס£Ð·¢²¼µÄ Perl/Tk ¼°Ê±µØÌáÐÑÄú¸ßÖÊÁ¿ÓÐʱºò°éËæ×ÅÒ×ÓÃÐÔ¡£¡¡¡¡¡¡¡¡Äú¿ÉÒ԰Ѿ«Á¦¼¯ÖзÅÔڸ߲úÁ¿µÄ·þÎñÆ÷¶Ë±à³ÌÉÏ£¬¶øÓÐʱÈÔÈ»¿ÉÑ¡Ôñʹ½çÃæ¸üƯÁÁ¡£´ËÍ⣬ÇáÁ¿¼¶¹¤¾ßÏ䣨ÀýÈç Perl/Tk£©Ê¹ÕâÑù×ö³ÉΪ¿ÉÄܲ¢ÇÒʹÄú²»±Ø¸¶³ö¸üΪÒýÈËעĿµÄ GUI ·½·¨µÄ´ú¼Û¡£¡¡¡¡¡¡¡¡
¹¤¾ßÏä×ÝÀÀ¡¡¡¡´ú¼ÛÊÇʲô£¿Ò»°ãÀ´Ëµ£¬Óë GUI µÄ¶ÔÓ¦µÄÃæÏòÃüÁîÐеÄÇ×ÆÝÏà±È£¬GUI µÄ±à³Ì¡¢²âÊÔ¡¢ÒÆÖ²ºÍ²¿Êð¸üΪÀ§ÄÑ¡£ÈËÃǹ㷺ÈÏ¿É Microsoft Visual Basic£¨VB£©¶Ô GUI ¹¹ÔìµÄ¼ò»¯¡£È»¶ø£¬VB ʵ¼ÊÉϱ»¹ÂÁ¢ÔÚ Windows ÊÀ½çÖУ¬×÷ΪһÃűà³ÌÓïÑÔ£¬ËüÏÔµÃÓеã¼òª£¬ÕâЩÎÊÌâÔ¼ÊøÁË VB£»Èç¹ûÄúÏëÏêϸÁ˽âÕâЩȱµã£¬Çë²ÎÔı¾ÎÄĩβµÄ²Î¿¼×ÊÁÏ¡£ËäÈ» Java¡¢GTK+ ºÍ Qt Òѱ»ÈËÃǽÓÊܲ¢ÓÃÓÚ Linux ºÍÏà¹ØµÄ¿ª·ÅÔ´´úÂ뿪·¢£¬µ«ÊÇΪÁË¿ªÊ¼Ê¹ÓÃËüÃÇ£¬ÄúÐèÒª»¨È¥ºÜ¶àʱ¼äÀ´Ñ§Ï°²¢±àдºÜ¶àÐдúÂ룻ËüÃǵġ°½øÈëÃż÷¡±×è°ÁË´ÓÃæÏò×Ö·û±à³ÌÏò WIMP£¨windows-icons-menus-pointers£¬´°¿Ú-ͼ±ê-²Ëµ¥-Ö¸Õ룩±à³ÌµÄÇÄȻת±ä¡£¡¡¡¡¡¡¡¡ËäÈ»Óû§½»»¥µÄ Web Ä£Ð͹ýÓÚ¼ò»¯£¬µ«¶ÔÓÚÐí¶àСÈÎÎñÀ´Ëµ£¬ËüÒÑ×ã¹»ÁË¡£ÊÂʵÉÏ£¬ÎÒµÄ´ó²¿·Ö GUI ±à³ÌÊǹØÓÚ Web Ó¦ÓóÌÐòµÄ¡£¡¡¡¡¡¡¡¡È»¶ø£¬ÓÐʱºò Web µÄÄ£ÐÍÊDz»¹»µÄ¡£ÄúÐèÒª¸ü³ÉÊìµÄ¿É±à³ÌÐÔ»ò²»Í¬µÄ°²È«ÐÔÄ£ÐÍ¡£ÓÐʱºò£¬ÄúÖ»ÊÇÐèÒª¡°ÁíÒ»¸öÔ´¡±£»Web ·þÎñÆ÷µÄ»ùÓÚ Web µÄ¿ØÖÆÃæ°å»áʹϵͳ̫´àÈõ¡£ÓÐʱºò£¬Web µÄÄ£ÐÍÌ«´óÁË£º³£¼ûµÄ·þÎñÆ÷ºÍ¿Í»§»úʹÓúܶàÄÚ´æ²¢ÐèÒªÅäÖᣡ¡¡¡¡¡¡¡µ«ÊÇ£¬ÎÒÓкÃÏûÏ¢¡£Çë±£³Ö¸ß²úÁ¿µÄϵͳ±à³ÌÏ°¹ß¡£ÇëʹÓÃÇáÁ¿¼¶¸ß¼¶ÓïÑ԰󶨣¨ÀýÈç Perl/Tk »ò Tkinter£©¡£Äú½«µÃµ½ÄúÒÑ¿ª·¢µÄ³ÌÐòµÄ¿ÉÒÆÖ²µÄ¡¢¿Éά»¤µÄ¡¢¡°GUI »¯¡±µÄ°æ±¾£¬ÕâЩ°æ±¾Äܹ»Á¼ºÃµØÔËÐУ¬Äú½«¶Ô´Ë¸Ðµ½¾ªÆæ¡£¡¡¡¡¡¡¡¡ÎÞÂÛÄúϲ°®µÄÓïÑÔÊÇ Ruby »¹ÊÇ Fortran£¬ÕýÈ·µÄ¸½¼þ¶¼½«¸øÄúÀàËƵĻú»á¡£ÏÂÃæÊÇÒ»¸öÒÑÊìϤ Perl µÄ³ÌÐòÔ±³É¹¦µÄÀý×Ó¡£¡¡¡¡¡¡¡¡
×¼±¸Ñ§Ï° Perl/Tk¡¡¡¡ÄúÁ˽â Perl¡£ËüºÜ¼ò½à£¬¶øÇÒÕâÖÖ¼ò½àÊÇÇÉÃîµÄ£¬ÕâʹÄúÄÜÔÚÎå·ÖÖÓÄÚ±àд±¨¸æÉú³ÉÆ÷¡¢ÍøÂç̽²â¡¢Îı¾¹ýÂËÆ÷ºÍ½ø³Ì¼àÊÓÆ÷£¬Èç¹ûʹÓÃÆäËûÓïÑԵĻ°ÐèÒ»ÌìµÄʱ¼ä²ÅÄÜÍê³É¡£¡¡¡¡¡¡¡¡È»¶ø£¬Äú¿ÉÄܲ»ÖªµÀ£¬Ö»ÒªÔÙ¼Ó¼¸ÐдúÂ룬Äú¾ÍÄÜ°Ñ Perl Ó¦ÓóÌÐò±äΪ±íÏÖ³öÉ«¡¢Æ¯ÁÁµÄ GUI Ó¦ÓóÌÐò¡£ÔÚ developerWorks ÉÏÓÐһƪ Teodor Zlatanov µÄÎÄÕ£¨Çë²ÎÔIJο¼×ÊÁÏ£¬ÆäÖÐÓÐÕâƪÎÄÕµÄÁ´½Ó£©£¬ÕâƪÎÄÕÂÃèÊöÁË cfengine ºÍÏà¹ØµÄ Perl ʵÓóÌÐò£¬»¹ÎªÄúÑÝʾÈçºÎ±àдÒ×ÓõŤ¾ß£¬ÀýÈç¹Ø±ÕËùÓÐ inetd ½ø³ÌµÄ¶ÌСµÄ½Å±¾£º¡¡¡¡¡¡¡¡Çåµ¥ 1. kill_inetd.pl µÄÔ´´úÂë¡¡ ¡¡¡¡use Proc::ProcessTable;¡¡¡¡¡¡¡¡$t = new Proc::ProcessTable;¡¡¡¡¡¡¡¡¡¡foreach $p (@{$t->table}) {¡¡¡¡¡¡¡¡¡¡¡¡# note that we will also kill "xinetd" and all processes¡¡¡¡¡¡¡¡¡¡¡¡# whose command line contains "inetd"¡¡¡¡¡¡¡¡kill 9, $p->pid if $p->cmndline =~ 'inetd';¡¡¡¡}¡¡¡¡¡¡¡¡Èç¹ûÄúÐèÒª¹Ø±Õ¼¸¸öÓÐÎÊÌâµÄ CGI ½ø³Ì£¬Ôõô°ì£¿»òÕߣ¬Èç¹ûÄúÐèÒª±ÈÏ൱²Ð¿áµÄ¡°kill 9¡±¸üµÃÌåµØ·¢ËÍÐźţ¬Ôõô°ì£¿Èç¹ûÄú²»ÔÚµÄʱºòÄúµÄÀÏ°å»òºó±¸ÈËÔ±ÐèҪʹÓÃÕâ¸ö½Å±¾£¬Ôõô°ì£¿´«Í³µÄ´ð°¸ÊÇ´ò¿ª±à¼Æ÷¡¢°Ñ inetd Ìæ»»³É cgi µÈ£¬È»ºó´ÓÃüÁîÐÐÔÙ´ÎÔËÐÐ perl kill_inetd.pl¡£¡¡¡¡¡¡¡¡È»¶ø£¬Çë°ÑµÚÒ»¸öÇ嵥ת»»³ÉÇåµ¥ 2£º¡¡¡¡¡¡¡¡Çåµ¥ 2. Ð޸ĺóµÄ kill_inetd.pl µÄÔ´´úÂë¡¡ ¡¡¡¡¡¡¡¡use Proc::ProcessTable;¡¡¡¡use Tk;¡¡¡¡¡¡ ¡¡¡¡¡¡ ¡¡¡¡sub kill_them {¡¡¡¡¡¡¡¡$t = new Proc::ProcessTable;¡¡¡¡¡¡¡¡¡¡foreach $p (@{$t->table}) {¡¡¡¡¡¡¡¡¡¡¡¡kill $signal, $p->pid if $p->cmndline =~ $keyWord;¡¡¡¡¡¡¡¡}¡¡¡¡¡¡¡¡$result_text = "Signal $signal sent to all '$keyword' processes.";¡¡¡¡}¡¡¡¡¡¡¡¡$main = MainWindow->new();¡¡¡¡$main->Label(-text =>¡¡¡¡¡¡¡¡¡¡"Control panel for killing processes\n¡¡ enter keyword here")->pack();¡¡¡¡$main->Entry(-textvariable => \$keyword)->pack();¡¡¡¡$radiobutton_frame = $main->Frame->pack();¡¡¡¡$radiobutton_frame->Radiobutton(-text => "KILL",¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ -variable => \$signal,¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ -value => 9)->pack(-side => left);¡¡¡¡$radiobutton_frame->Radiobutton(-text => "TERM",¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ -variable => \$signal,¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ -value => 15)->pack(-side => left);¡¡¡¡$main->Button(-text => "Send kill signal to named processes",¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡-command => \&kill_them)->pack();¡¡¡¡$main->Label(-textvariable => \$result_text)->pack();¡¡¡¡¡¡¡¡¡¡¡¡# Set reasonable defaults.¡¡¡¡$keyword = "inetd";¡¡¡¡$signal = 9;¡¡¡¡¡¡¡¡MainLoop();¡¡¡¡¡¡¡¡µ±ÄúÔÚÔËÐÐÇåµ¥ 2 ʱ£¬Äú½«µÃµ½Ò»¸ö½ÏСµÄµ«ÓÐÓÃµÄ GUI ¿ØÖÆÃæ°å£º ¡¡¡¡¡¡¡¡
¼òµ¥µÄÐźŷ¢ËÍ¿ØÖÆÃæ°å¡¡¡¡ ¡¡¡¡Óû§°ÑËüµ¯³öÒ»´Îºó¾Í¿ÉÒÔ·½±ãµØʹÓÃËü¶ø²»±ØÔÙÊäÈë¡£¡¡¡¡¡¡¡¡²»¹ý£¬Çë×¢ÒâÕâ¶þʮһÐеĽű¾ÎªÄúÊ¡È¥µÄ¶«Î÷£ºÄúûÓг¤´ï¼¸Ò³µÄÉùÃ÷ºÍÅäÖá£ÄúûÓÐÈκÎÐí¿ÉÖ¤ÏÞÖÆ£¨³ýÁËÄúÊìϤµÄ Perl Ðí¿ÉÖ¤£©¡£Äú²»±ØѧϰеÄÓïÑÔ¡£¡¡¡¡¡¡¡¡
еĵØƽÏß¡¡¡¡ÕâÊÇÁîÈËÐ˷ܵĶ«Î÷¡£Äú¿ÉÒÔʹÓüò¶ÌµÄ GUI ½Å±¾À´°ü×°ËùÓеġ¢ÏÖ´æµÄ¡¢Óà Perl ´úÂë±àдµÄÓ¦ÓóÌÐòÒÔʹËüÃdzÉΪͬÑù½»»¥µÄ¡¢¡°·½±ãÓû§¡±µÄ³ÌÐò¡£ÊÂʵÉÏ£¬Äú¿ÉÒÔÈÝÒ×µØÖØдÄúÏÖÓеÄʵÓóÌÐòÒÔʹËüÃÇÄܹ»ÔÚÊÕµ½ºÏÊʵÄÃüÁîÐвÎÊýʱ¼ÌÐøÒÔÕý³£µÄ¡°Åú´¦Àí¡±·½Ê½ÔËÐУ¬µ«ÔÚÆäËûÇé¿öÏÂÄܹ»Ö´ÐÐÁíÒ»¸ö·ÖÖ§²¢¹¹Ôì GUI ´°¿Ú£º¡¡¡¡¡¡¡¡Çåµ¥ 3. ÔÚÃüÁîÐÐÓë GUI ²Ù×÷Ö®¼ä×÷³öÑ¡Ôñ¡¡¡¡ ¡¡¡¡¡¡¡¡ ¡¡¡¡sub batch_operation {¡¡¡¡ ¡¡¡¡}¡¡¡¡¡¡¡¡ ¡¡¡¡sub start_GUI {¡¡¡¡ ¡¡¡¡¡¡ use Tk;¡¡¡¡ ¡¡¡¡¡¡ ...¡¡¡¡ ¡¡¡¡¡¡ MainLoop();¡¡¡¡¡¡¡¡¡¡¡¡}¡¡¡¡¡¡¡¡ ¡¡¡¡if (0 == scalar(@ARGV)) {¡¡¡¡ start_GUI();¡¡¡¡ ¡¡¡¡}¡¡¡¡ ¡¡¡¡if (errors_detected_in_@ARGV()) {¡¡¡¡ start_GUI();¡¡¡¡ ¡¡¡¡}¡¡¡¡ ¡¡¡¡batch_operation();¡¡¡¡ ¡¡¡¡Çë¼Çס£ºÎªÁËÈ¡µÃÕâЩ½á¹û£¬ÄúÖ»ÐèÌí¼Ó¼¸ÐÐÄúÒÑÖªµÀµÄ Perl£¨»ò Python »ò¡¡£©´úÂë¡£´ËÍ⣬ÒòΪ¶ÔÓÚÍⲿӦÓóÌÐòÀ´Ëµ£¬Perl Æ𵽡°Õ³ºÏ¼Á¡±µÄ×÷Óã¬ËùÒÔÕâЩ¼¼Êõ¿É±»ÓÃÀ´°ü×°Äú²»ÏëÅöµÄ¾ÉµÄ Fortran »ò C Ó¦ÓóÌÐò¡£ÄúÖ»ÐèÓÃÒ»µã´øÓз´ÒýºÅ£¨backtick£©»ò exec µÄ Perl À´°ü×°ËüÃǾͿÉÒÔÁË¡£¡¡¡¡¡¡¡¡Perl/Tk »¹Óв»´íµÄ¿ÉÉìËõÐÔ¡£È«ÊÀ½çÿÌìÕýÔÚʹÓôóÁ¿µÄ Perl/Tk Ó¦ÓóÌÐò£¬°üÀ¨Éú»¯Ä£ÄâÆ÷¡¢µØͼ»æÖƳÌÐò¡¢º½°à¹ÜÀíϵͳµÈ¡£±í´ï´ó¹æÄ£µÄ Perl/Tk ±à³ÌµÄ¸Ð¾õÊÇÀ§Äѵġ£ÒÔÉϵÄʾÀýÑÝʾÁËͨ¹ýÌí¼Ó¼¸ÐÐ Perl À´¡°GUI »¯¡±ÊǶàôµÄÈÝÒס£Èç¹ûÄúÏë¸ü³ä·ÖµØÌå»á¡°´ó¹æÄ£¡±µÄ Perl/Tk ±à³ÌµÄ¸Ð¾õ£¬Çë²ÎÔÄÏÂÃæµÄ²Î¿¼×ÊÁÏÖеIJο¼Êé²¢×Ô¼ºÑо¿¸üΪ¸´ÔӵijÌÐòµÄÔ´´úÂë¡£¡¡¡¡¡¡¡¡Ò»¸öÎÒ»¹Ã»Ð´µÄ³ÌÐò£¨ËäÈ»ÎÒÒÑдÁËÕâ¸ö³ÌÐòµÄÔʼµÄÔÐÍ£©ÊÇ Zlatanov µÄÒÅ´«Ë㷨ģÄâÆ÷£¨ÇëÔĶÁËûÔÚ developerWorks ·¢±íµÄÎÄÕÂÖÐÓйØÕâ¸öÄ£ÄâÆ÷µÄÄÚÈÝ£¬ÕâƪÎÄÕ±»ÁÐÔڲο¼×ÊÁÏÖС££©µÄͼÐΰ汾¡£×÷ΪÁ·Ï°£¬¶ÁÕß¿ÉÒÔ±àдһ¸ö¸üÁîÈËÂúÒâµÄ°æ±¾¡£ÎÒ×Ô¼ºµÄʵÑ鰵ʾÕ⽫ÊDZ¾×¨À¸ËùÍƼöµÄ·½·¨µÄ·¶Àý£ºµ±ËüµÄÅú´¦Àí·½Ê½µÄ²Ù×÷ÔÚÒ×ÓÃµÄ Perl/Tk Canvas С´°¿ÚÉϱ»¿ÉÊÓ»¯Ê±½«±äµÃȷʵºÜÉú¶¯¡£¡¡¡¡¡¡¡¡Èç¹ûÄúÔÚ¼¸ÄêÇ°¾ÍÊÔÓùý Perl/Tk ÇÒ Perl/Tk û¸øÄúÁôÏÂÉî¿ÌµÄÓ¡Ïó£¬ÄÇôÏÖÔÚÊÇÔÙ¸ø Perl/Tk Ò»´Î»ú»áµÄʱºò¡£×î½ü Perl/Tk µÄ´¦ÀíÆ÷ÓÐÁ˺ܴóµÄ¸Ä½ø¡£¶ÔÓÚ Perl/Tk µÄ³õѧÕßÀ´Ëµ£¬ÔÚÁ÷ÐеÄƽ̨ÉÏ°²×°¶þ½øÖÆÎļþµÄ¹ý³Ì±»´ó´óµØ¼ò»¯£¬Windows µÄ¿ÉÒÆÖ²ÐÔÒ²ÓÐÁ˸ÄÉÆ£¬×îеķ¢ÐаæµÄÖÊÁ¿¸ü¸ß¡£ÓÐ¹Ø Perl/Tk µÄÊéÔ½À´Ô½¶à£¬ÕâÒ»µãÒ²Ðí¸üΪÖØÒª¡£O'Reilly ÔÚÆßÔÂÍƳöÁË Perl in a Nutshell µÄµÚ¶þ°æ£¬ÆäÖÐÓб¦¹óµÄ Perl/Tk µÄ²Î¿¼×ÊÁÏ¡£×îºÃµÄÏûÏ¢ÊÇ O'Reilly ÔÚ 2002 Äê³õ³ö°æÁËÓÉ Nancy Walsh ºÍ Stephen Lidie ±àдµÄ Mastering Perl/Tk¡£Èç¹ûÄú×¼±¸½Ï³¤Ê±¼äµÄʹÓà Perl/Tk£¬ÄÇô Mastering Perl/Tk ÊÇÒ»±¾ÄúÐèÒª¹ºÂòµÄ²Î¿¼Êé¡£¡¡¡¡¡¡¡¡
½áÊøÓï¡¡¡¡ÔÚϵͳ³ÌÐòÔ±ºÍ¹ÜÀíÔ±¿´À´£¬GUI ¹¤×÷¿ÉÄÜÓеãÉñÃØ¡£ËüÀàËÆÓÚרҵµÄ¹¤×÷£¬ÕâÖÖ¹¤×÷²»°üÀ¨ÎÒÃÇÒ»°ãÔÚ¡°·þÎñÆ÷ÕïËù¡±ÖнøÐеÄÄÇЩ¿ª·¢¡£¡¡¡¡¡¡¡¡È»¶ø£¬Ëü²»±ØÊÇÄǸöÑù×Ó¡£ÀàËÆ Perl/Tk µÄÏÖ´úµÄ GUI ¹¤¾ßÏäÌṩÁ˲»´íµÄÐÔÄܺ͹¦ÄÜÒÔ¼°±¾×¨À¸¾³£Ç¿µ÷µÄ¸ß²úÁ¿ºÍÒ×ѧÐÔ¡£ÇëÄúÔÚÕâ¸öÔ»¨Ò»Á½¸öСʱ£¬¸ø Perl/Tk Ò»´Î°ïÄú°ü×°³ÌÐòµÄ»ú»áÒÔʹ³ÌÐò¸üÓÐÎüÒýÁ¦¡£
[1] [2] ÏÂÒ»Ò³
£¨³ö´¦£ºhttp://www.sheup.com£©
ÉÏÒ»Ò³ [1] [2]