本文介绍了为什么Perl不支持用双引号插入散列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 #!/ usr / bin / perl 
使用警告;

my%hash =(no1=> 1,
no2=> 2,
);

print%hash; #Prints no11no22
print%hash; #Prints%hash

为什么Perl不支持双引号内的散列插入?它支持标量($),数组(@)的插值,那么为什么不用于散列(%)呢?解析方案

散列stringify?标量是显而易见的,也是数组。但是散列应该是什么?这样的字符串化会有多大用处?它是否比使用插值字符串中未转义的%字符更有用或更少?是否值得花费大量的工作来修复今天在插入字符串中使用%的所有代码?



如果您能对这些问题提出良好的答案,那么我相信P5P会愿意听他们的。


#!/usr/bin/perl
use warnings;

my %hash=("no1"=>1, 
        "no2"=>2,
      );

print %hash; #Prints no11no22
print "%hash"; #Prints %hash

Why doesn't Perl support interpolation of a hash within double quotes? It supports interpolation for scalars ($), arrays (@) then why not for hashes (%)?

解决方案

How should a hash stringify? Scalars are obvious and arrays too. But what should a hash be? How useful will such a stringification be? Is it more or less useful than being able to use a % character unescaped in an interpolating string? Is it worth the amount of work it will take to fix all of the code that uses % in interpolated strings today?

If you can come up with good answers to these questions, then I am sure P5P would be willing to listen to them.

这篇关于为什么Perl不支持用双引号插入散列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 05:48