0
当执行attatched码,进入˚F返回:Perl的奇怪行为时执行UNIX命令
Arthur Putie:923-835-8745:923-812-6789:23 Wimp Lane, Kensington, DL 38758:8/31/69:126000
Barbara Kertz:385-573-8326:385-555-8321:832 Ponce Drive, Gary, IN 83756:12/1/46:268500
Betty Boop:245-836-8357:245-876-7656:635 Cutesy Lane, Hollywood, CA 91464:6/23/23:14500
Ephram Hardy:293-259-5395:293-222-3334:235 CarltonLane, Joliet, IL 73858:8/12/20:56700
当进入升返回一样进入女,排序基于名字。
print "Please choose either first or last name (f/l): ";
$type = <>;
chomp($type);
if ($type == "f") {
system("sort list.txt");
} elsif ($type == "l") {
system("sort -k2 list.txt");
} else {
print "Choice not recognized.\n";
}
但是,如果我在UNIX手动执行命令,则命令出来排序,因为它们应该是,([排序LIST.TXT]是alphabatized第一名称,[排序-k2 LIST.TXT]是姓氏aplphabetized)。
为什么会出现这种情况的任何想法或解决方法?我是perl的新手,所以我宁愿坚持使用UNIX命令选项,而不是纯粹的perl脚本解决方案。
奇怪的是,解决了这个问题。你能帮我理解为什么会有这种效果吗? – Chris
@chris:[Perl运算符](http://perldoc.perl.org/perlop.html)我对其他答案不满意,比较运算符在这里描述。很高兴我能帮上忙。 – alexmac
感谢您的链接。 – Chris