First a word of advice on your formatting, you should surround code and formatted data with
<code> tags as otherwise it becomes difficult to read. You had to go through a preview page and must have seen this yourself, it should look more like this:
Data
names,age
Rahul,25
Manu,36
Vijay,41
Tushar,23
Hetal,54
Binoy,19
Vikram,16
Code
$file='a.csv';
open (a,$file) || die ("couldnt open file");
while ($line=<a>){
@array=split(/,/,$line);
@array1=split(/\n/,$array[1]);
@array2=sort {$a <=> $b}(@array1);
print "@array2";
}
This is just wrong, you should use the existing
Text::CSV module, however if this is home work you should do something like the following (assumes that names are unique)
- Read each line of the file into a hash of name=>agesplitting on ,
- Sort the hash by value using the Schwartzian transform(understanding how this works will enlighten you greatly)
print "Good ",qw(night morning afternoon evening)[(localtime)[2]/6]," fellow monks."