我在 Perl 中有一个问题:从给定的输入中读取一系列姓氏和电话号码。名称和数字应以逗号分隔。然后根据姓氏的字母顺序打印名称和数字。使用哈希。
#!usr/bin/perl
my %series = ('Ashok','4365654435' 'Ramnath','4356456546' 'Aniketh','4565467577');
while (($key, $value) = each(sort %series))
{
print $key.",".$value."\n";
}
我没有得到输出。我哪里错了?请帮忙。提前致谢
#!usr/bin/perl
my %series = ('Ashok','4365654435' 'Ramnath','4356456546' 'Aniketh','4565467577');
print $_.",".$series{$_}."\n" for sort keys %series;
如果我执行上述 2 个程序中的任何一个,我会得到与以下相同的输出:
String found where operator expected at line 2, near "'4365654435' 'Ramnath'" (Missing operator before 'Ramnath'?)
String found where operator expected at line 2, near "'4356456546' 'Aniketh'" (Missing operator before 'Aniketh'?)
syntax error at line 2, near "'4365654435' 'Ramnath'"
Execution aborted due to compilation errors
但根据问题,我认为我无法将输入存储为my %series = ('Ashok','4365654435','Ramnath','4356456546','Aniketh','4565467577');