Gossamer Forum
Home : General : Perl Programming :

sort question

Quote Reply
sort question
Hi Folks,

I really really need your help on oneproblem I have. I need to use the perl sort function but within a rather tricky situation.

The chunck of code opens up every file within a directory and then reads the information within that file and prints it. But I want the program to print the files in alphabetical order.

I want the program to sort the output on alphabetical order of the second variable within each file. Get what I mean?

Here's the code I have now......

<CODE>
opendir (DIR,"$E_DATA_DIR");
@files = grep (!/^\.\.?$/, readdir (DIR));
closedir (DIR);

foreach $file (@files) {
push(@sites,$file);
}


foreach $site (@sites) {

open (FILE2,"$E_DATA_DIR/$site");
@filedata2 = <FILE2>;
close (FILE2);

$fields = join('',@filedata2);

@fields = split(/\|/,$fields);

$dat_id = $fields[0];
$e_dat_name = $fields[1];

</CODE>

...

I need to sort the output on the field $e_dat_name but I'm stuck as how to do this.

Please can someone shed any light on this task?

Thankyou for your help.

Wil.