* 日曜日の 2 回目の更新*
この時点で、目的のサブを表示することに成功したことがわかりました 。コードの新しいスニペットにより、必要に応じて特定のサブを実際に呼び出すことができました。
調査中に、着信FORMデータの読み取りを処理する次のスニペットを見つけました。このスニペットは、このスクリプトから選択したサブルーチンの呼び出しを有効にします。しかし、CLI からスクリプトに対して perl -xを実行すると、システムは次の致命的でない *警告* を返します。これを理解して解決したいと考えています。私の調査によると、 (tr///)と $ENV{"REQUEST_METHOD"}と$bufferが空の値"" OR 0を返しています。これらの次のエラーを解決するにはどうすればよいですか? への参照を削除できることに気づきました (tr///)と$bufferを使用してこれらのエラーを解決しますが、 *$ENV{"REQUEST_METHOD"}*を削除することは、このスニペットの機能にとって必須のように思われるので疑問です???
CLI エラー
Use of uninitialized value in transliteration (tr///) at test.pl line 36 (#1) Use of uninitialized value $ENV{"REQUEST_METHOD"} in string eq at test.pl line 37 (#1) Use of uninitialized value $buffer in split at test.pl line 44 (#1)
#!/usr/bin/perl -w
# (test.pl)
use DBI;
use DBD::mysql;
use warnings;
use strict;
use diagnostics;
$| = 1;
# The script I am wanting to create, is to allow users at (NAS) HotSpot to create a user account
# which is to write into MySQL db TABLE's *radcheck* and *radreply*.
#
# Now at this point I have found some added success at displaying the desired *sub*
# The new snippet of code which enabled me to actually *invoke* a specific *sub* as I wanted
# from an HTML form.
# Please see below for solution which still has some questions.
print "Content-type: text/html\n\n";
sub BuildAcctNow {
print "<h1 style=\"color:blue;font-family:Arial;font-size:xx-large;\">TO BUILD YOUR ACCOUNT TODAY WE WILL NEED A SMALL AMOUNT OF INFORMATION</h1><br><br>\n\n";
}
sub PauseAcctNow {
print "<h2 style=\"color:red;font-family:Arial;font-size:xx-large;\">YOUR ACCOUNT HAS BEEN PAUSED PLEASE MAKE A PAYMENT HERE.</h2><br><br>\n\n";
}
# In researching I stumbled upon the fllowing snippet which deals with reading inward FORM data.
# This snippet *does* enable the *invocation* of the *sub* of my choice from this script.
# However from the CLI when I run perl -x against the script the system returns the following
# *nonfatal* *warnings* that I would like to gain understading of and resolve.
# My research shows that (tr///) and $ENV{"REQUEST_METHOD"} and $buffer are returning empty
# values, How would I best resolve these following errors? I realize I can just delete any
# reference to (tr///) and $buffer to resolve those errors, howerver I question removing
# $ENV{"REQUEST_METHOD"} as it seems this imperative to the function of th ssnippet???
#
#
# Use of uninitialized value in transliteration (tr///) at test.pl line 36 (#1)
# Use of uninitialized value $ENV{"REQUEST_METHOD"} in string eq at test.pl line 37 (#1)
# Use of uninitialized value $buffer in split at test.pl line 44 (#1)
my ($buffer, @pairs, $pair, $name, $value, %FORM);
# Read in text
$ENV{'REQUEST_METHOD'} =~ tr/a-z/A-Z/;
if ($ENV{'REQUEST_METHOD'} eq "POST")
{
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
}else {
$buffer = $ENV{'QUERY_STRING'};
}
# Split information into name/value pairs
@pairs = split(/&/, $buffer);
foreach $pair (@pairs)
{
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%(..)/pack("C", hex($1))/eg;
$FORM{$name} = $value;
}
if ($FORM{PauseAcct}) {
PauseAcctNow();
exit;
}
elsif ($FORM{BuildAcct}) {
BuildAcctNow();
exit;
}
第二日曜日の更新を終了
日曜日の更新 ** この時点で私がやろうとしていることをうまく表現できるように、簡単なスクリプトを作成しました。最終的に作成する必要があるスクリプトは、MySQL db のradcheckとradreplyに書き込み、ユーザーが (NAS) HotSpot にログオンできるようにします。したがって、スクリプト内に複数のサブルーチンがあります。
BuildAcctという名前のドキュメント内で適切な名前の SUBMIT フォームを含む HTML ドキュメントを使用すると、スクリプトは現在、空の画面 VIA ブラウザを表示します。
私は伝統的にスクリプト内でサブを定義することに慣れており、スクリプト内でifテストを定義します。これは、定義されたフォーム名からの一致を待機し、それらが相互作用して特定のサブ。
以下は、 subを呼び出すときの時代遅れの & の使用を乗り越えようとして作成したテスト スクリプトです。
#!/usr/bin/perl -w
# (test.pl)
use DBI;
use DBD::mysql;
use warnings;
#use strict;
# Presently due to my errors below I have disabled *use strict*.
$| = 1;
# The script I am wanting to create, is to allow users at (NAS) HotSpot to create a user account
# which is to write into MySQL db TABLE's *radcheck* and *radreply*.
#
# Trying to bring myself up to speed with a very basic task which I have defined below, in my
# older scripts I would define the *sub* itself, then in the script I would use an *if* test
# which checks to see if any defined FORM value returns a hit such as $form_data{'BuildAcct'} ne ""
# to call the required *sub* _ThisOne_.
print "Content-type: text/plain\n\n";
sub ThisOne {
print "Trying to display this subroutine upon submission of BuildAcct\n";
}
# Following is the *if* test I am accustomed to using to make a call to a particular sub when
# the form NAME BuildAcct is interacted with, but this is unacceptable now I realize.
# CLI Return:
# Use of uninitialized value $form_data{"BuildAcct"} in string ne at test.pl line 32.
# Use of uninitialized value $form_data{"BuildAcct"} in string ne at test.pl line 41.
if ($form_data{'BuildAcct'} ne "")
{
&ThisOne;
exit;
}
# SO, I have Google'd, and looked over numerous methods of calling *subs*, I am just stuck though,
# Why can't the following *if* test work if use of & is no longer used?
if ($form_data{'BuildAcct'} ne "")
{
ThisOne();
exit;
}
よろしくお願いします...よろしくお願いします
更新 **
スクリプトの -w スイッチをオフにしました。これが悪影響を与えるかどうかはわかりませんが、perl にとってはかなり新しいものです。
また、醜い不格好なコードもいくつか作成しました。奇妙なことに、CLI からスクリプトを実行すると、システムから次のように返されます。
Use of uninitialized value $form_data{"BuildAcct"} in string at acctmanager.pl line 211.
Use of uninitialized value $form_data{"Test"} in string at acctmanager.pl line 212.
それでも、HTML ドキュメントからの VIA ブラウザでは、SUBMIT名の値をBuildAcctとTestの間で前後に変更でき、スクリプトは送信時に 2 つの異なる正しいサブルーチンを正常に返します。
BuildAcctサブルーチンは、そのサブルーチン内で定義したフォーム フィールドを返しますが、TestはMySQL TABLE GROUP 行フェッチを実行し、データベースから 3 つの異なるテーブルを表示して、それらをブラウザーに出力します。
以下は私の現在のコードです:-(
local ($form_data{'BuildAcct'}) = "$form_data{'BuildAcct'}";
local ($form_data{'Test'}) = "$form_data{'Test'}";
#
# AddNewUser FORM definition.
if ($form_data{'BuildAcct'} ne "")
{
&AddNewUser;
exit;
}
#
# DispTest FORM definition.
elsif ($form_data{'Test'} ne "")
{
&DispTest;
exit;
}
誰かが私に正しい方向への微調整を与えることができますか?
よろしくお願いします
ORIGINAL POST
この時点で、BuildAcctという名前の HTML ドキュメントに FORM があります。同様に、スクリプト内で、ユーザーが HTML FORM を送信したときにサブルーチンAddNewUserを呼び出す次のように定義しました...
if ($form_data{'BuildAcct'} ne "")
{
&AddNewUser;
exit;
}
スクリプトはcgi-lib.plを使用します
# Enable parsing of FORM_DATA VIA cgi-lib.pl.
&ReadParse(*form_data);
## FORM or IMG FORM Fix
foreach (keys %form_data)
{
## Fix incoming form data with Image buttons
$form_data{$1} = $form_data{$_} if (/(.*)\.x/);
}
私が理解できないのは、私が使用する別のスクリプトでこれが機能する理由ですが、この新しいスクリプトは CLI で実行すると次のように返されます。
Use of uninitialized value $form_data{"BuildAcct"} in string ne at acctmanager.pl line 208.
Use of uninitialized value $form_data{"Test"} in string ne at acctmanager.pl line 215.
ヘルプと提案は大歓迎です。よろしくお願いします