perl:在哈希值中使用逗号

sid*_*rma 0 string perl hash

我将键值对作为"statement:test,data",其中'test,data'是hash的值.在尝试使用这些值创建哈希时,perl会分割逗号上的值.有没有办法解决这个问题,可以使用带逗号的字符串作为值

mvp*_*mvp 5

Perl中没有任何东西阻止您使用'test,data'作为哈希值.如果您的传入字符串字面上是"statement:test,data",则可以使用此代码添加到哈希:

my ($key, $value) = ($string =~ /(\w+):(.*)/);
next unless $key and $value;  # skip bad stuff - up to you
$hash{$key} = $value;
Run Code Online (Sandbox Code Playgroud)