fufaso has asked for the wisdom of the Perl Monks concerning the following question:
What I am doing is storing that list as an array:YEAR MAKE MODEL PRICE 2003 abc rel 999 1999 hds sdf 100 2010 kls pol 1400
I want to run the program and take a user input that says YEAR, MAKE, PRICE and sort it accordingly. Here's what I've tried, but was not right was it is separating the columns and storing them together as oppose to sorting by column while keeping the rows intact.@inventory=('2003 abc rel 999', '1999 hds sdf 100', '2010 kls pol 1400');
Any tips on how to make this work would be great!$lookfor=<STDIN>; chop($lookfor); foreach $inv (@inventory) { ($YEAR,$MAKE,$MODEL,$PRICE)=split(/ /, $inv); push (@year,$YEAR); push (@make, $MAKE); push (@price, $PRICE); } if ($lookfor =~ /year/i){ @sorted = sort @year; print join "\n",@sorted; print "\n"; } if ($lookfor =~ /make/i){ @sorted = sort @make; print join "\n", @sorted; print "\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Inventory List Sorting Question
by GrandFather (Saint) on Sep 23, 2010 at 00:51 UTC | |
|
Re: Inventory List Sorting Question
by BrowserUk (Patriarch) on Sep 22, 2010 at 22:41 UTC | |
|
Re: Inventory List Sorting Question
by Anonymous Monk on Sep 22, 2010 at 22:48 UTC | |
by fufaso (Initiate) on Sep 22, 2010 at 23:19 UTC |