我是Perl新手。比方说,我有一个包含这样的值的数组:Perl排序和正则表达式
@array = ("2014 Computer Monitor 200", "2010 Keyboard 30", "2012 Keyboard 80", "2011 Study Desk 100");
我将如何使用Perl的正则表达式的一年,项目名称和价格对整个数组进行排序?例如,如果用户想通过价格排序他们输入“价格”,它排序是这样的:
2010 Keyboard 30 2012 Keyboard 80 2011 Study Desk 100 2014 Computer Monitor 200
到目前为止,我已经能够在今年这样的排序:
@array = ("2014 Computer Monitor 200", "2010 Keyboard 30", "2012 Keyboard 80", "2011 Study Desk 100"); $input = ; chomp($input); if ($input eq "year") { foreach $item (sort {$a cmp $b} @array) { print $item . "\n"; } }
你可以发布你写来尝试解决这样的代码? StackOverflow不是免费的编码服务。人们更愿意回答有关您的代码的问题,而不是为您编写或调试整个事情。 – chilemagic 2014-09-27 04:59:00