有人可以帮助我理解这个Perl程序的输出:
use Data::Dumper;
my %hash;
$hash{hello} = "foo";
$hash{hello}{world} = "bar";
print $hash{hello} . "\n";
print $hash{hello}{world} . "\n";
print Dumper(\%hash);
Run Code Online (Sandbox Code Playgroud)
并输出:
foo
bar
$VAR1 = {
'hello' => 'foo'
};
Run Code Online (Sandbox Code Playgroud)
"foo"来自哪里?怎么没有翻斗车打印出来?
请注意,如果我交换作业的顺序:
use Data::Dumper;
my %hash;
$hash{hello}{world} = "bar";
$hash{hello} = "foo";
print $hash{hello} . "\n";
print $hash{hello}{world} . "\n";
print Dumper(\%hash);
Run Code Online (Sandbox Code Playgroud)
我的输出是我所期望的:
foo
$VAR1 = {
'hello' => 'foo'
};
Run Code Online (Sandbox Code Playgroud)
编辑:我知道use strict;会抓住这个,但我更感兴趣的是知道如何打印字符串"foo".
好的,我有3个表,称之为:
人
商店
PersonStore
现在,我有一个表单,允许您向一个人添加商店.但是,我从表单中获取商店ID.我真的不想进行查询以从Entity Framework获取商店对象.我只想使用StoreID和Person对象添加到表中.
我目前正在使用ProcessBuilder从java服务器运行命令.此服务器将替换旧的Perl服务器,并且我们的许多遗留代码指定了特定于平台的命令行.
例如,在Windows上它可能会:
command -option "hello world"
Run Code Online (Sandbox Code Playgroud)
在unix上它可能会:
command -option 'hello world'
Run Code Online (Sandbox Code Playgroud)
问题是ProcessBuilder和Runtime.exec都为unix和windows接受了标记化的命令行(例如,{"command"," - option","hello world"}).
虽然我更喜欢平台独立的方式,但我们的代码库中有大约3000万行perl代码.如果没有我为不同的平台编写一个标记器(真的不是很重要,我只是不想制作WTF),有没有办法让操作系统上的shell标记命令行?
这是我的代码 -
Dim provider As CultureInfo = CultureInfo.InvariantCulture
Dim a1 As DateTime = Nothing
insexp = DateTime.ParseExact(date1.SelectedValue, "MMMM yyyy", provider)
If a1.Month = Today.Month AndAlso a1.Year = Today.Year Then
a1 = Today.Date
End If
Run Code Online (Sandbox Code Playgroud)
这仅在date1.selectedvalue不为null时才有效,但如果为null则会崩溃.如果条件不运行,我该怎么办?谢谢
以下是重现问题的代码:
sub hello { return (h => 1, n => 1); }
print join ", ", values hello();
Run Code Online (Sandbox Code Playgroud)
我收到错误:
arg 1到值的类型必须是第4行的哈希(不是子例程条目),靠近");" 执行 - 由于编译错误而中止.
我知道我可以打破电话和打印两行:
sub hello { return (h => 1, n => 1); }
my %hash = hello();
print join ", ", values %hash;
Run Code Online (Sandbox Code Playgroud)
但我不想这样做.有没有办法在一行中执行此操作,以便我不必一直创建临时变量?
我有一行文字看起来像hh^ay-pau+h@ow,我想提取文本之间-,并+在这种情况下pau。这应该在bash中完成。任何帮助,将不胜感激。编辑:我想提取第一次出现的令牌之间的文本PS:我的Google搜索并没有带我去任何地方。如果这个问题已经提出,我深表歉意。