0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Perl: CGI.pm の使い方

Last updated at Posted at 2021-03-22

CGI.pm を使って、アクセスした URL を取得する方法です。

test_script.pl
# ! /usr/bin/perl
#
#	test_script.pl
#
use strict;
use CGI;

my $query = CGI->new;
my $SelfUrl   = $query->self_url;
#
my $file_out = "/var/log/apache2/perl/perl_aa.txt";
open (OUT,">$file_out");
binmode OUT, ":encoding(UTF-8)";
print OUT "*** test_script.pl *** start ***\n";
print OUT "*** test ***\n";
print OUT $SelfUrl . "\n";
print OUT "*** Mar/22/2021 PM 18:29  ***\n";
print OUT "*** test_script.pl *** end ***\n";
close (OUT);
#
print STDERR "*** test_script.pl *** start ***\n";
print STDERR "*** Mar/22/2021 PM 18:27 ***\n";
#
print "Content-type: text/html; charset=utf-8\n\n";
print "*** test_script.pl ***<br />\n";
print "Hello<br />\n";
print "Good Morning<br />\n";
print "Mar/22/2021 PM 15:59<br />\n";
print "<p></p>\n";
#
print STDERR "*** test_script.pl *** end ***\n";
#

実行すると次のようなファイルが作成されます。

/var/log/apache2/perl/perl_aa.txt
*** test_script.pl *** start ***
*** test ***
https://example.com/cgi-bin/test_virtual.php
*** Mar/22/2021 PM 18:29  ***
*** test_script.pl *** end ***

Arch Linux で CGI.pm をインストールする方法

sudo pacman -S perl-cgi

関連ページ
Apache2 の PHP で virtual を使う
Apache2 の PHP で virtual を使う (ファイル書き込み)

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?