JANコード | 4 | 9 | 0 | 2 | 7 | 7 | 7 | 1 | 3 | 0 | 8 | 3 | 5 |
偶数桁 | 9 | 2 | 7 | 1 | 0 | 3 | |||||||
奇数桁 | 4 | 0 | 7 | 7 | 3 | 8 |
my $jan = "XXXXXXXX..."; # JANコード my $cc; # 企業コード $cc = $+ if $jan =~ /^((45[6-8]\d{6})\d{4}|(45[0-5]\d{4}|49\d{5})\d{6}|(\d{6})\d\d)$/; # MEMO: $+ は最後にマッチした文字列を返す
#!/usr/bin/perl -T use strict; use warnings; use CGI; use HTML::Template; my $filename = "(TEXTFILENAME)"; my $n = 100; my $q = new CGI; my $from = $q->param('f') || 1; my $next_line = $from + $n; my $pre_line = ($from - $n > 1) ? $from - $n : 1; open(my $fh, "<", $filename) or die; my $str = ""; while (<$fh>) { next if $. < $from; last if $. >= $from + $n; $str .= $_; } close($fh); my $template = join("", <DATA>); my $t = HTML::Template->new(scalarref => \$template, global_vars => 1, die_on_bad_params => 0); $t->param(from => $from); $t->param(str => $str); $t->param(next_line => $next_line); $t->param(pre_line => $pre_line); print $q->header(-charset => 'UTF-8'), $t->output(); __DATA__ <html lang="ja"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Large Text File Viewer</title> </head> <body> <a href="?f=<TMPL_VAR name=pre_line>"><<</a> <a href="?f=<TMPL_VAR name=next_line>">>></a> <hr> <pre><TMPL_VAR name=str></pre> <hr> <a href="?f=<TMPL_VAR name=pre_line>"><<</a> <a href="?f=<TMPL_VAR name=next_line>">>></a> </body> </html>