1, "no2"=>2, ); print %hash; #Prints no...">

Why doesn't Perl support double quotation hash interpolation?

#!/usr/bin/perl use warnings; my %hash=("no1"=>1, "no2"=>2, ); print %hash; #Prints no11no22 print "%hash"; #Prints %hash 

Why doesn't Perl support double-quote hash interpolation? It supports interpolation for scalars ($), arrays (@), why not for hashes (%)?

+7
source share
3 answers

How should a hash be scribbled? Scalars are obvious and arrays too. But what should be the hash? How useful would such a strobification be? Is this more or less useful than being able to use the% unescaped character in an interpolation string? Is it worth the effort to fix all the code that% uses in interpolated lines today?

If you can find good answers to these questions, I am sure that P5P will want to listen to them.

+15
source

To quote Nathan Thorkington: "The big problem is that% is heavily used in double-quoted strings with printf." More info here .

+21
source

Not quite the answer to the question β€œwhy,” but I thought I wanted to point out the various answers to the β€œhow.”

You can, of course, try:

 #!/usr/bin/perl use warnings; use strict; my %hash = ( "no1" => 1, "no2" => 2, ); print "@{[ %hash ]}\n"; 

But I do not know what use will be.

If you want to dump the contents of a hash or any other complex data structure, use Data :: Dumper or YAML or JSON depending on your use case.

+4
source

All Articles