主功能:
my %hash = {'inner1'=>{'foo'=>5},
'inner2'=>{'bar'=>6}};
$object->State(0, %AMSValues);
Run Code Online (Sandbox Code Playgroud)
寄去:
sub State
{
my ($self, $state, %values) = @_;
my $value = \%values;
Run Code Online (Sandbox Code Playgroud)
据我所知,一个应该是哈希,另一个是指针,但......

它看起来不像是这样的,
$value = $value->{"HASH(0x52e0b6c)"}
%values = $values->{"HASH(0x52e0b6c)"}
Run Code Online (Sandbox Code Playgroud) 我自己制作了一个自定义PERL模块,当它被同一目录中的脚本调用时,它可以工作,但出于某种明显的原因,它不能从目录外部调用.如何在不安装模块的情况下使用该模块?例如:
use 5.012;
use warnings;
use Y:/my/dir/to/module.pm;
Run Code Online (Sandbox Code Playgroud) 我试图以动态方式传递参数.我想使用Perl函数given(){},但出于某种原因我不能在其他任何东西中使用它.这就是我所拥有的.
print(given ($parity) {
when (/^None$/) {'N'}
when (/^Even$/) {'E'}
when (/^Odd$/) {'O'}
});
Run Code Online (Sandbox Code Playgroud)
现在我知道我可以在此之前声明一个变量并在print()函数内部使用它,但我正在尝试使用我的代码更清洁.同样的原因我不使用复合if-then-else语句.如果它有助于这里的错误
syntax error at C:\Documents and Settings\ericfoss\My Documents\Slick\Perl\tests\New_test.pl line 22, near "print(given"
Execution of C:\Documents and Settings\ericfoss\My Documents\Slick\Perl\tests\New_test.pl aborted due to compilation errors.
Run Code Online (Sandbox Code Playgroud) 我似乎比我原先想象的更像是C++中的菜鸟.就我对C/C++的了解而言,这应该有效.我定义了一个字符数组,然后尝试指定一个开头的指针......我做错了什么?
// Create character array
char str[] = "t xtd 02 1CF00400 08 11 22 33 44 55 66 77 88 0 0 1234.567890";
// Assign pointer to beginning of array
char* p = &str;
Run Code Online (Sandbox Code Playgroud) 假设我有一个Perl脚本:
my $hash = {};
$hash->{'a'} = {aa => 'b'};
$hash->{'b'} = undef;
for (qw(a b c)) {
if(defined $hash->{$_}->{aa})
{
say "defined $_";
}
else
{
say "undef $_";
}
}
print Dumper $hash;
Run Code Online (Sandbox Code Playgroud)
但是我的输出会自动创建'c',这是我不想要的.
defined a
undef b
undef c
$VAR1 = {
'c' => {},
'a' => {
'aa' => 'b'
},
'b' => {}
};
Run Code Online (Sandbox Code Playgroud)
我的发行版也不允许我禁用自动修复.有没有办法制作一个检查每个级别的子程序?
假设我有一个Perl模块My::Module:
package My::Module;
sub foo {
return $module_name;
}
Run Code Online (Sandbox Code Playgroud)
我会怎么替换$module_name用得到My::Module?
很多硬件都附带一个Tx/Rx状态LED,但如果您的硬件没有,并且您想查看数据是否正在传输,该怎么办?如果您只是将LED设置为线的值,它可能会在您看到之前打开和关闭(<1/100秒).
我的问题是,如何编写中断驱动功能来驱动LED状态?我搜索了互联网,什么都没找到,我可以使用一个模数计数器,但这看起来很笨重.还有其他想法吗?
PS - 我想在Arduino或Mbed中使用它,但我怀疑它对于哪一个问题有所不同......
### Code Here ###
use 5.012;
use warnings;
my @a = (1, 'Ah');
say (@a ~~ /^1$/ ? 'TRUE' : 'FALSE');
say ('1' ~~ @a ? 'TRUE' : 'FALSE');
say (@a ~~ "Ah" ? 'TRUE' : 'FALSE');
say (@a ~~ /^Ah$/ ? 'TRUE' : 'FALSE');
### STDOUT ###
TRUE
TRUE
FALSE
TRUE
Run Code Online (Sandbox Code Playgroud)
这些都不应该通过吗?
为什么Perl没有捕获此异常?
my $fh;
eval { close $fh };
warn('Caught') if &@;
Run Code Online (Sandbox Code Playgroud)
输出:
Can't use an undefined value as a symbol reference at New_test.pl line 30.
Run Code Online (Sandbox Code Playgroud)
更新:没有警告线的相同输出,eval { close $fh };是第30行.
我知道Perl keys()函数,并希望在我拥有的哈希上使用它,但是没有看到任何设置变量的理由.让我用代码解释两种方式:
正常:
my %hash = ReturnsHash();
foreach (keys(%hash)) {
...code...
}
Run Code Online (Sandbox Code Playgroud)
我喜欢的方式:
foreach (keys(ReturnsHash())) {
...code...
}
Run Code Online (Sandbox Code Playgroud)
用第二种方法我得到这个错误信息(Type of arg 1 to keys must be hash or array (not subroutine entry))第二种方式可能吗?如果是这样的话?
perl ×8
hash ×2
perl-module ×2
pointers ×2
arduino ×1
c ×1
c++ ×1
char ×1
char-pointer ×1
embedded ×1
exception ×1
function ×1
led ×1
regex ×1
transmission ×1