文档下载 文档下载导航
设为首页 | 加入收藏
搜索 请输入内容:  
 导航当前位置: 文档下载 > 所有分类 > IT/计算机 > Perl语言高级编程专题15.prn
侵权投诉

Perl语言高级编程专题15.prn

Spring, 2010

Both"GET" and"POST" method Useful Environment Variables: REQUEST_METHOD& QUERY_STRING

Spring, 2010

Perl语言高级编程专题 Lesson 15 周晓方 courses@xfzhou.homeftp.org

Data fetching and decoding

$Method=$ENV{'REQUEST_METHOD'};#CGI方法 if ($Method eq"POST"){#读取数据 read(STDIN,$QueryString,$ENV{'CONTENT_LENGTH'});} else{$QueryString=$ENV{'QUERY_STRING'};}@NameValuePairs= split(/&/,$QueryString); foreach$NameValue (@NameValuePairs){……见前页……#解码} 2

1

Debugging CGI script If returns script itself If"page not found" or"URL not exists" – Check"action=…." in form see if link is correct

Spring, 2010

Let's debug a script 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22.#!/usr/bin/perl -w use stirct; my($Method,$DataLen,$QueryString,@NameValuePairs,$Name,$Value);$Method=$ENV{'REQUEST_METHOD'}; if ($Method eq"POST"){ read(STDIN,$QueryString,$ENV{'QUERY_STRING');} else{$QueryString=$ENV{'QUERY_STRING'};}@NameValuePairs= split(/&/,$QueryString); foreach$NameValue (@NameValuePairs){ ($Name,$Value)= split(/=/,$NameValue);$Value=~ tr/+//;$Value=~ s/%([\dA-Fa-f]{2})/pack("C",hex($1))/eg; print"Name=$Name, Value=$Value<br>\n";} 1;

Spring, 2010

Return a web page that displays all name=value pairs.

– Property of server& CGI's not set properly.– Missing the she-bang line (#!) in the beginning of script

If server returns a blank page: – Check cgierr.txt (under xitami http server)– Run on console mode for syntax checking

If the result is not expected: –"print" on result page– Use 3rd part tools (e.g. perlbuilder)

3

4

A counter 顺序:open-read-close-open-update-close 1. 2. 3. 4. 5. 6. 7. 8. 9.

Spring, 2010

Multi-task and Critical Session Issues under multi-task environment: –––– A sequence of operation not interruptible A seq. of operation not allow task-switching Exclusive access to a shared resource<<< Inter-task/process/thread communication……

Spring, 2010

open(COUNT,"MyCount");$count=<COUNT>; close(COUNT); open(COUNT,">MyCount");$count++; print COUNT$count; close(COUNT); print"<html><body>count is$count</body></html>"; 1; open-read-close-open-update-close A Critical Session临界区域 5

Solutions: –禁止中断/调度Disable interruption/task switch–互斥量、旗语(信号量)Mutex/Semaphores–直接利用文件系统的独享打开文件的操作 use Fcntl;$lockfile="mycount.lockfile"; unlink$lockfile; sysopen(LOCKFILE,$lockfile, O_WRONLY| O_EXCL| O_CREAT) or die"Another instance already running!";#或者sleep and re-try………… close($lockfile);

问题:多进程环境Multiple instance of counter.pl –

6

Uasing CGI.pm

Spring, 2010

CGI.pm, CGI interface – doc.guandang.net

Spring, 2010

use CGI qw/:standard/; Interface to GET/POST, http, cookies, etc

Get all the keys and values:@keys= param( ); foreach$key (@keys){ print"$key=>", param($key),"\n";} For multiple choice:@values= param($key); And lots more in CGI.pm 7

预装的未必是最新的,升级到CGI.pm v3.29 #!/usr/bin/perl use CGI qw/:standard/;@keys= param( ); foreach$key (@keys){ print"$key=>", join(",", param($key)),"\n";}#@values= param($key); 1; 8

Get key and values from client

Perl语言高级编程专题15.prn

第1页

你可能喜欢

热门文档

相关文档

  • Perl语言高级编程专题13.prn

    最小TK程序 use TK; my $mw=MainWindow->new()->MainLoop; Spring, 2007 Perl语言高级编程专题 Lesson 13 周晓方 courses@xfzhou.homeftp.org ? 安装情况...

  • Perl语言高级编程专题

    Spring, 2008 Perl语言高级编程专题 Lesson 10 周晓方 courses@xfzhou.homeftp.org 《Perl调试技巧》清华大学出版社2001年 (Peter Scott, Ed Wright, "Perl ...

  • Perl语言高级编程专题11

    Spring, 2007 Perl语言高级编程专题 Lesson 11 .o r 周晓方 courses@xfzhou.homeftp.org x fz P e rl ho u. h o me Perl和网络,Perl和Win32 1 ftp...

  • Perl语言高级编程专题14

    Spring, 2007 Perl语言高级编程专题 Lesson 14 .o r 周晓方 courses@xfzhou.homeftp.org x fz P e rl ho u. h o me ftp g 1 Web browser & Http ...

  • Perl语言高级编程专题

    Perl语言高级编程专题 Lesson 10 周晓方 courses@xfzhou.homeftp.org Perl调试技巧 (Peter Scott, Ed Wright, "Perl Debugged") 1 对Perl程序员的忠告 ? 区分...

  • Perl语言高级编程专题09.prn

    Perl语言高级编程专题09.prn 隐藏>> MAC地址, IP地址, 端口号 ? MAC地址: – 网卡绑定的唯一48bit地址,六段16进制表示 Perl语言高级编程专题 Lesson 9 周...

  • Perl语言编程

    Perl语言编程_计算机软件及应用_IT/计算机_专业资料 暂无评价0人阅读0次下载举报文档 Perl语言编程_计算机软件及应用_IT/计算机_专业资料。详细介绍Perl语言,有...

  • 第十五章 perl语言编程

    作者:刘才林 第 1 页共 44 页 完成于 2008/3 月 第十五章 15.1:Perl 简介: Perl 语言编程 Perl 是 Practical Extraction and Report Language(实用摘录和...

  • PERL 语言完美编程

    PERL 语言完美编程_调查/报告_表格/模板_实用文档。编程PERL 语言完美编程简洁... Perl语言编程(大骆驼) 520页 1下载券 Perl语言高级编程专题04 4页 免费 ...

  • 【论文】可编程控制器的高级编程语言

    可编程控制器的高级编程语言_专业资料。本文重点介绍了两种基于西门子公司开发的可编程控制器的高级编程语言S7-Graph和S7-HiGraph。文章主要集中在介绍它们的编程原则...

站点地图 | 文档上传 | 侵权投诉 | 手机版
本站所有资源均来自互联网,本站只负责收集和整理,均不承担任何法律责任,如有侵权等其它行为请联系我们.
文档下载 Copyright 2013 doc.guandang.net All Rights Reserved.  -  email