-4
我想寫一個perl腳本有一個菜單,用戶在列表中選擇一個(1-3),然後要求用戶輸入一個字符串(取決於所選的菜單)這應該被讀作輸入並在控制檯中打印。但是在執行腳本時,我發現這個錯誤。這裏有什麼可能是錯的?Perl腳本返回錯誤全局符號需要明確的包
~] # perl sample.pl
Global symbol "$user" requires explicit package name at ./sample.pl line 26.
Global symbol "$user" requires explicit package name at ./sample.pl line 27.
Global symbol "$user" requires explicit package name at ./sample.pl line 28.
Global symbol "$process" requires explicit package name at ./sample.pl line 37.
Global symbol "$process" requires explicit package name at ./sample.pl line 38.
Global symbol "$process" requires explicit package name at ./sample.pl line 39.
Missing right curly or square bracket at ./sample.pl line 52, at end of line
syntax error at ./sample.pl line 52, at EOF
Execution of ./sample.pl aborted due to compilation errors.
#!/usr/bin/perl
use strict;
use warnings;
use Switch;
my $input = '';
while ($input ne '3')
{
clear_screen();
print "1. user\n".
"2. process\n".
"3. exit\n";
print "Enter choice: ";
$input = <STDIN>;
chomp($input);
{
case '1'
{
print "Enter user";
$user = <STDIN>;
chomp ($user);
print "User is $user\n";
}
case '2'
{
print "Enter process:";
$process = <STDIN>;
chomp ($process);
print "Process is $process\n";
}
}
http://perlmaven.com/global-symbol-requires-explicit-package-name – 2014-10-31 09:35:23
請勿使用開關http://stackoverflow.com/questions/2630547/why-is-the-switch-module- deprecated-in-perl – 2014-10-31 09:37:22
你的[編輯](http://stackoverflow.com/posts/26671362/revisions)完全改變了這個問題,你的縮進是可怕的。精益基本編程http://learn.perl.org – 2014-10-31 10:17:37