gpt4 book ai didi

perl - 脚本不识别全局变量

转载 作者:行者123 更新时间:2023-12-02 08:24:49 25 4
gpt4 key购买 nike

我在下面有一个程序,我正在尝试测试它:

#! usr/bin/perl    
#MOA is our company module
#the perl is running for windows 7

use strict;
use warnings;

use Getopt::Long;
use MOA::CLSUtils;
use MOA::PamReport;
use MOA::PamJobs;
use Data::Dumper;
use Time::HiRes qw(gettimeofday);
use Date::Pcalc;
use File::Path qw(make_path remove_tree);

#declare global varibles

my (%menu_sections, %menu_section, %menu_items, %menu_index);

#initialize global variables
%menu_sections = (

#initialize hash
);
%menu_items =(#initialize hash);
my $TERM_WIDTH = 44; #declare variables and initialize
my ($section, $item, $knote);
my $count = 1;
my $submenu="N";

#foreach loop compare keys
#the code below is trying to print menu for users
foreach $section (sort {$a cmp $b} keys %{menu_sections}) {
if (($count == 1) && ($submenu eq "N")) { #if statement
}
else { #else statement
$knote = "";
}
#print on the screen using category function
print "\n\t", category($section, $knote), "\n", "\t", "-" x length($section), "\n";
#the second key print using category function
foreach $item (@{$menu_sections->{$section}}) { #line 36 go through hash and code don't recognize hash

printf("\t%3s ) %-15s %-30s\n", $item, $menu_items->{$item}->[0], $menu_items->{$item}->[1]); #line 38 print menu
}
$count++; #count lines
} #end of the code

当我运行它时,我收到消息:

Global symbol "$menu_sections" requires explicit package name at test.pl line 36
Global symbol "$menu_items" requires explicit package name at test.pl line 38
Global symbol "$menu_items" requires explicit package name at test.pl line 38
Execution of test.pl aborted due to compilation errors.

我不明白,为什么Perl不识别全局变量

最佳答案

$menu_sections->{$section} 访问由标量 $menu_sections 中的引用引用的散列元素。您打算访问哈希 %menu_sections 的元素。您应该使用过 $menu_sections{$section}

另一个错误是一样的。

关于perl - 脚本不识别全局变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33176681/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com