open(LOG,"logfile.txt") or die "Unable to open $logfile:$!";
print "\n";
while(<$LOG>){
print if /\berror\b/i;
}
close(LOG);
Run Code Online (Sandbox Code Playgroud) 我正在编译这个方法:
#changes the names of the associations for $agentConf
#where the key value pairs in %associationsToChangeDict are the old and new values respectively
sub UpdateConfObjectAssociations{
my($agentConf, %associationsToChangeDict) = @_;
foreach my $association ($agentConf->GetAssociations()) {
if ( grep {$_ eq $association->Name()} keys %associationsToChangeDict) {
my $newValue = %associationsToChangeDict{$association->Name()};
$association->Value($newValue);
}
}
}
Run Code Online (Sandbox Code Playgroud)
这是错误消息:
syntax error at D:\Install\AutoDeployScripts\scripts\Perl/.\AI\SiteMinderHelper
.pm line 75, near "%associationsToChangeDict{"
syntax error at D:\Install\AutoDeployScripts\scripts\Perl/.\AI\SiteMinderHelper
.pm line 79, near "}"
Run Code Online (Sandbox Code Playgroud)
任何人都可以看到问题出在哪里?
我有这个输出 Dumper
'group' => {
'1104' => {
'a' => 1
},
'52202' => {
'b' => 1,
'c' => 1
},
'52201' => {
'c' => 1
},
'52200' => {
'c' => 1
}
},
Run Code Online (Sandbox Code Playgroud)
我假设是哈希数组哈希?
我想宣布这个结构是我自己的.
有没有办法做到这一点,所以下次我看到这么复杂的结构时,我可以立刻做到这一点?=)
我正在将哈希传递给各种子例程,我想知道如何将哈希传递给子例程,然后将该子例程中的相同哈希传递给不同的子例程,依此类推.
例如,以下代码工作正常.
use strict;
use warnings;
my %hash = (
key1 => 'value1',
key2 => 'value2',
key3 => 'value3',
key4 => '',
);
print %hash, "\n";
check_it(\%hash);
sub check_it {
my $params = shift;
foreach(keys %{$params}){
if($params->{$_}) {
print "'$_' defined as '$params->{$_}'\n";
}
else {
print "'$_' not defined as '$params->{$_}'. Deleting it.\n";
#delete $params->{$_};
$params->{$_} = 'null';
}
}
for ( my $i = 0 ; $i < 7 ; $i++ ) {
print "looping\n";
&check_tags_again(\%hash);
}
} …Run Code Online (Sandbox Code Playgroud) 我在理解子程序语法时遇到了困难.
使用以下代码:
sub build_dyne_file{
open(DYNAP, "+>$veri_dir/$dyna_para") or die $!;
for (keys %hash){
print DYNAP "#define ",$_," ",$hash{$_}->[$i],"\n";
}
close(DYNAP);
}
for (my $i = 0 ; $i <$TEST_QUOTA ; $i++){
build_dyna_file($i);
}
Run Code Online (Sandbox Code Playgroud)
在'build dyne file'子例程中,'for循环'遍历散列键,而$ i参数在外部'for循环'中使用.
我希望你理解这个问题,如果没有 - 我会试着更恰当地解释它.
谢谢你的回答.