Perl:字符串不转义反斜杠
我无法理解这样一个简单的陈述我做错了什么。问题发生在以下行:
$this->_validate_hash($hashref->{$key}, $schemaref->{$key}, $path . (ref($hashref->{$ key}) ? $key . "\\\@$key"), $errors);
所以我希望事情以 /path/to/some/\@attribute< /代码>。然而,我现在得到的是
path/to/some/\\@attribute
。我在最后一部分尝试了各种组合,包括 '\\' 。 '@'。 $key
或 '\@' 。 $key
或 '\\@' 。 $key
但我仍然无法逃脱反斜杠。这是我不知道的 Perl 字符串中的一些怪癖吗?谢谢。
I cannot understand what I'm doing wrong with such a simple statement. The problem occurs on the line:
$this->_validate_hash($hashref->{$key}, $schemaref->{$key}, $path . (ref($hashref->{$key}) ? $key . "/" : "\\\@$key"), $errors);
So I want things to end with /path/to/some/\@attribute
. However, what I'm getting at the moment is path/to/some/\\@attribute
. I tried various combos for the last part including '\\' . '@' . $key
or '\@' . $key
or '\\@' . $key
but I still can't escape the backslash. Is this some quirk in perl strings that I'm not aware of? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这不是一个简单的陈述;它分为两行,包含各种内容。正如我所看到的,这实现了相同的结果(假设
$xpath
未在脚本中的其他地方使用):但是,它更接近可读 - 仍然不是特别容易,但更具可读性比原来的。
你的问题孩子似乎可以减少到:
代码工作干净:
所以,要么我有一个不同的 Perl(这是 Linux x86/64 上的 5.12.1),要么你的设置中有一些不同。鉴于我们没有所有的哈希值等,很难得到它 - 但你应该以类似的方式分解你的问题。
That is not a simple statement; it is split over two lines and contains all sorts of stuff. This achieves the same result, as near as I can see (and assuming
$xpath
is not used elsewhere in your script):However, it is more nearly readable - still not particularly easy, but much more readable than the original.
Your problem child can be reduced, it seems, to:
That code works cleanly:
So, either I've got a different Perl (this was 5.12.1 on Linux x86/64) or there is something different in your setup. Given that we don't have all the hashes etc, it will be hard to get at it - but you should break down your problem in an analogous way.