无法使用包含单引号的键从存储中检索数据

Unable to retrieve data from stash with key that contains a single quote

数据库包含名称中带有单引号的公司名称。当用户选择一家公司时,我需要使用键=CompanyName 从散列中检索。我遇到的问题是无法从 Stash 中检索内容。

在调试模式下,我验证了以下内容,能够在公司名称周围使用单引号和双引号:

  DB<12> x $c->stash->{'company_list'}->{'corp_summary'}->{'Waldo\\'s Merchandising Services, LLC'}
0  'c635|i1193|i1194|i1220|i1221|'
  DB<13> x $c->stash->{'company_list'}->{'corp_summary'}->{"Waldo\\'s Merchandising Services, LLC"}
0  'c635|i1193|i1194|i1220|i1221|'

代码打印出我正在寻找的名字和我已经完成的替换,但最后一行代码“$codes”仍然是空的。

306       print "$cc\n";
307       print "$cc\n";
308       print "$cc\n";
309       print "$cc\n";
310       my $temp = $cc;
311       $temp =~ s/'/\/\/\/\'/g;
312       
313       print "$temp\n";
314       print "$temp\n";
315       print "$temp\n";
316       print "$temp\n";
317       print "$temp\n";
318       my $codes = $c->stash->{'company_list'}->{'corp_summary'}->{"$temp"};

打印语句的输出:

Waldo's Merchandising Services, LLC
Waldo's Merchandising Services, LLC
Waldo's Merchandising Services, LLC
Waldo's Merchandising Services, LLC
Waldo///'s Merchandising Services, LLC
Waldo///'s Merchandising Services, LLC
Waldo///'s Merchandising Services, LLC
Waldo///'s Merchandising Services, LLC
Waldo///'s Merchandising Services, LLC

我的预期输出是让 $codes 包含 "c635|i1193|i1194|i1220|i1221|"

您使用的是正斜杠而不是反斜杠,并且您的斜杠比 $temp 中需要的多两个。尝试:

$temp =~ s{'}{\'}g;