強引な「require」

                             <p>ソースコード</p>
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/usr/bin/perl

#BEGIN{
#   print "Content-type: text/plainnn";
#   open(STDERR, ">&amp;STDOUT");
#   $|=1;
#}

$timeBegin = times;
$usr_title = 'テスト27';

require "tsenv.pl";

{
    printHeader($usr_title);
    printBodyHeader($usr_title);

    Jprint('ほげてすと<br>');
    Jprint('ちゃんとJISで表示されてますか?<br><br>');
#   print Jcode->new('げほてすと<br>これもJISですか?')->jis;

    printFooter();

    exit(0);
}
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# tsenv.pl : TestCGI向き共通設定

init() unless defined $info_copyright;

sub init{
#   use Jcode;
    unshift(@INC, '../..');
    require 'jcode.pl';

    $info_copyright='';
    open(IN, "../../sig.txt");
    <IN>;
    while(<IN>){
        $info_copyright .= $_;
    }
    close(IN);

    $usr_outcode = 'jis' unless defined $usr_outcode;# 'sjis';# 'euc';# 'utf8';
    if($usr_outcode eq 'sjis'){
        $usr_outCharset = 'shift_jis';
    }elsif($usr_outcode eq 'jis'){
        $usr_outCharset = 'iso-2022-jp';
    }elsif($usr_outcode eq 'euc'){
        $usr_outCharset = 'euc-jp';
#   }elsif($usr_outcode eq 'utf8'){
#       $usr_outCharset = 'utf-8';
    }

    $usr_exTitle = $usr_title . 'の解説';
    $usr_ex = $ENV{SCRIPT_NAME};
    $usr_ex =~ s|cgi/(ts[0-9]{4})(_[12u])?.cgi$|$1.htm|;

    @usr_stylesheet = (
        '../../ipp.css',
        '../test.css',
    );

#   %usr_links = (
#       'Home'            =>   '../../../index.htm',
#       'Perl'            =>   '../../',
#       'TestCGI Index'   =>   '../',
#       $usr_exTitle    =>   $usr_ex,
#   );
    @usr_linkName = (
        'Home',
        'Perl',
        'TestCGI Index',
        $usr_exTitle,
    );
    @usr_linkAddr = (
        '../../../index.htm',
        '../../',
        '../',
        $usr_ex,
    );
}

sub printHeader{
# 「<title>タグ」の文字列
    my($title) = @_;
    my $ss = '';
    $ss .= qq(<link rel="stylesheet" type="text/css" href="$_">n) foreach @usr_stylesheet;
    Jprint(<<EOM);
Content-type: text/html; charset=$usr_outCharset

<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html lang=ja>
<head>
<meta name="ROBOTS" content="NOINDEX">
<meta http-equiv="Content-type" content="text/html; charset=$usr_outCharset">
<meta http-equiv="Content-style-type" content="text/css">

<title>$title</title>

<link rev="made" href="$info_mailAddr">
$ss
</head>
<body>
EOM
}

sub printBodyHeader{
# 英字なら「printBodyHeader("<font face=times>Title String</font>");」がいいんだけど・・・。
    my($title) = @_;
    print "<div align=center>n";
    Jprint(qq(<h2><a name="top">$title</a></h2>n<hr>n));
    printLinks();
    print "</div>n";
    print "<div class=test>nn";
}

sub printFooter{
    print "n</div>n";
    print "<div align=center>n";
    print qq(<a href="#top" class=en>Top</a>n<hr>n);
    printLinks();
    print "</div>n";
    print "n<div align=right>n";
    printf("Cost : %.2f<br>n", times);
    print $info_copyright;
    print "n</div>n</body>n</html>nn";
}

sub printLinks{
#   my $cnt = 0;
#   foreach(sort keys %usr_links){
#       print "/ " if $cnt++;
#       Jprint(qq(<a href="$usr_links{$_}">$_</a>n));
#   }

#   for($i=0; $i<@usr_linkName; $i++){
    foreach $i(0 .. $#usr_linkName){
        print "/ " if $i;
        Jprint(qq(<a href="$usr_linkAddr[$i]" class=en>$usr_linkName[$i]</a>n));
    }
    print "<hr>n";
}

sub Jprint{
#   print Jcode::convert($_, $usr_outcode) foreach(@_);
    print jcode::to($usr_outcode, $_) foreach @_;
}

1;
                          </div>
comments powered by Disqus
Built with Hugo
テーマ StackJimmy によって設計されています。