tutimura@mist.i.u-tokyo.ac.jp kaneko@ipl.t.u-tokyo.ac.jp http://www.misojiro.t.u-tokyo.ac.jp/ tutimura/sem3/ 2002 11 20 p.1/34
10/16 1. 10/23 2. 10/30 3. ( ) 11/ 6 4. UNIX + C socket 11/13 5. ( ) C 11/20 6. http, CGI Perl 11/27 7. ( ) Perl 12/ 4 8. Windows Winsock 12/11 9. JAVA 12/18 10. ( ) JAVA 11. 12. ( ) p.2/34
HTTP (Hyper Text Transfer Protocol) web web HTML FTP, SMTP 0.9, 1.0, 1.1 (C)atmarkIT p.3/34
HTTP web Internet Explorer Netscape (Mozilla), Opera lynx, w3m wget, iria Googlebot LWP (Perl), java.net (Java), libwww (C ) socket IO::Socket (Perl), java.net (Java), socket(c) telnet p.4/34
HTTP web Apache IIS (Internet Information Services) LWP (Perl) socket IO::Socket (Perl), java.net (Java), socket(c) p.5/34
HTTP TCP/IP "GET /index.html HTTP/1.0\n\n" GET HEAD POST Content-Type: text/html HTML Content-Type: image/jpeg JPEG p.6/34
HTTP (stateless) ASCII p.7/34
CGI (Common Gateway Interface) HTTP web web web Perl SSI (Server Side Include), Java Servlet, ASP (Active Server Pages) p.8/34
vs CGI (C)atmarkIT p.9/34
CGI CGI GET POST CGI Content-type HTML CGI p.10/34
CGI GET "? = & = " HTML <a href="hoge.cgi?a=1">link</a> POST HTML form p.11/34
Apache CGI CGI HTTP CGI CGI /cgi-bin/ CGI.cgi,.pl CGI chmod +x hoge.cgi CGI p.12/34
vs CGI CGI HTTP p.13/34
OS OS p.14/34
Perl Larry Wall, version 5 (5.004, 5.6) UNIX MS-Windows Mac CPAN (Comprehensive Perl Archive Network)... p.15/34
Perl hello world print "hello world\n"; @array = <STDIN>; for ( $i=$#array; $i>=0; $i-- ) { print $array[$i]; } print reverse(<stdin>); p.16/34
#!/usr/local/bin/perl -w UNIX # ; {} my $hoge; p.17/34
_ 12345 10.56.23E-10 0xffff 16 p.18/34
$hoge @hoge $hoge[0] %hoge $hoge{ zero } 1 $a = "4 + 1"; $b = 4 + 1; print "$a = $b\n"; 1 4 + 1 = 5 2 @array = ("zero", 1, "two"); print "@array\n"; print "$array[2]\n"; 2 zero 1 two two p.19/34
"" $i = 5; print "$i th edtion\n"; # 5 th edition print "${i}th edtion\n"; # 5th edition print $i\n ; # $i\n p.20/34
(1) if ( ) {} while ( ) {} ( unless) ( until) do {} while ( until) else if elsif {} switch perl if ( 1 ) { 1; } elsif ( 2 ) { 2; } else { ; } p.21/34
(2) if, unless, while, until for, foreach next, last $b=1 if $a==0; # if ($a==0) { $b=1; } for ($i = 0; $i < 10; $i++) { next if ( $a[$i] == 0 ); last if ( $a[$i] == -1 ); } for my $elem (@elements) { $elem *= 2; } # # p.22/34
C + - * / % = ++ -- += -= *= /= %= ** **= C << >> & ˆ ==!= < > <= >= eq ne lt gt le ge! && not and or xor. p.23/34
$_ @_ @ARGV $ARGV[0] $ARGV[$#ARGV] shift $0 STDIN STDOUT STDERR %ENV p.24/34
if ("a") if ("") if (<STDIN>) if ("0") p.25/34
-e file -f file -d file -r file -w file while (@ARGV) { my $f = shift @ARGV; if ( -d $f ) { print "$f\n"; } } # # $f # # p.26/34
=! $string = /pattern/; $string = s/hoge/fuga/gi; $string = tr/abcdef/abcdef/; p.27/34
$i = mul_add(2, 3, 4); # $ i = 2 * 3 + 4; print "$i\n"; # 10 sub mul_add { # @_ my ($x, $y, $z) = @_; # $x $y $z return $x * $y + $z; } p.28/34
open(in, "< input"); # input open(out,"> output"); # output while(<in>) { # IN $_ print OUT $_; # OUT $_ } # $_ close(out); # OUT close(in); # IN open open(in, "ls "); # ls open(out, " sort >> out"); # out... p.29/34
print, printf, chop, chomp open, close, system exit, die sleep rand, srand, int man perl man perlfunc p.30/34
CGI Content-type CGI GET hoge.cgi?number=123 123 CGI IP #!/usr/local/bin/perl -w use CGI qw/:standard/; my $child_number = param( number ); my $child_host = remote_host(); print "Content-type: text/plain\n\n"; print "Your number is $child_number.\n"; print "You are working on $child_host.\n"; p.31/34
#!/usr/local/bin/perl -w use Fcntl :flock ; # LOCK_*... open(inout, "+< $datafile"); # flock(inout, LOCK_EX); # $in = <INOUT>; #... seek(inout, 0, 0); # print INOUT "$out\n"; # truncate(inout, tell(inout));# # sleep(10); # close(inout); # close p.32/34
[1] Perl ISBN4-900900-48-6 Larry Wall, Tom Christiansen, Randal L. Schwartz,, [2] Perl http://flex.ee.uec.ac.jp/texi/perl-nyuumon/ p.33/34
Apache 8Mbyte Apache CGI CGI p.34/34