perl encapsulate single variable in double quotes

后端 未结 5 1574
南方客
南方客 2021-01-12 11:06

In Perl, is there any reason to encapsulate a single variable in double quotes (no concatenation) ?

I often find this in the source of the program I am working on (w

5条回答
  •  隐瞒了意图╮
    2021-01-12 11:57

    In this case the double quotes are unnecessary. Moreover, using them is inefficient as this causes the original strings to be copied.

    However, sometimes you may want to use this style to "stringify" an object. For example, URI ojects support stringification:

    my $uri = URI->new("http://www.perl.com");
    my $str = "$uri";
    

提交回复
热议问题