I have an array that contains values like this:
@array = ("2014 Computer Monitor 200", "2010 Keyboard 30", "2012 Keyboard 80", "2011 Study Desk 100");
How would I use regular expressions in Perl to sort the entire array by year, item name, and price? For example, if the user wants to sort by price they type 'price' and it sorts like this:
2010 Keyboard 30 2012 Keyboard 80 2011 Study Desk 100 2014 Computer Monitor 200
So far I've been able to sort by year like this:
@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"; } }