某所での会話:
13:14 <#perl6> t****: y'know, one thing that got me into Ruby was that the CGI library would
auto-detect that I was testing it in a browser and take arguments as if I
was working in a browser. Made troubleshooting a breeze...
13:14 <#perl6> t****: I mean, testing from the command line...
13:15 <#perl6> t****: I always wished the perl CGI module would do that...
13:16 <#perl6> P*******: eh?
13:17 <#perl6> t****: When you write a ruby cgi program, and run it from the command line, it detects
that you are in a command line and allows you to input stuff that it would normally
get from the URL string.
13:17 <#perl6> t****: Maybe there is a way to do this with the perl cgi module,
but I never learned how.
13:17 <#perl6> P*******: perl's CGI module has always done that.
13:18 <#perl6> P*******: you simply pass name=val on the command line
13:18 <#perl6> P*******: (or you could set some environment variables)
13:18 <#perl6> t****: hm... Wish I had known that then...
ええええええええええ。この機能ってすごい有名だと思ってた。
普通にCGI.pmのスクリプトはコマンドラインから実行できるお>< デバッグとかにはとても便利です!
#!/usr/bin/perl
use strict;
use CGI;
my $q = CGI->new();
print $q->header(-content_type => 'text/plain', -charset => 'utf-8'),
"Hello, ", $q->param('name') || "NoName", "!\n"
こんなスクリプトを、以下のように実行すると、"Hello, lestrrat!"と本文に表示されます
% perl test.cgi name=lestrrat
Content-Type: text/plain; charset=utf-8
Hello, lestrrat!
簡単!・・・まぁ、最近は生CGIでなんか書くってのもなくなってきたけどね
カテゴリ
日常トラックバック(0)
このブログ記事に対するトラックバックURL: http://mt.endeworks.jp/cgi-bin/mt-tb.cgi/2429


コメントする