1
我想使用變量的值(例如通過命令行選項修正)作爲列表分隔符,啓用該值是一個特殊字符(換行符,製表等)
不幸的是,天真的做法不會因爲這兩個以下print語句的行爲differentely工作的事實:
my @tab = ("a","b","c");
# block 1 gives expected result:
# a
# b
# c
{
local $" = "\n"; #" let us please the color syntax engine
print "@tab";
}
# block 2 gives unwanted result:
# a\nb\nc
{
use Getopt::Long;
my $s;
GetOptions('separator=s' => \$s);
local $" = "$s"; #" let us please the color syntax engine
print "@tab";
}
任何想法,我可以修正塊2,以便得到想要的結果(由塊1產生的結果)?