Let me try and explain what I’m trying to achieve.
I have a file containing a list of filenames and other information such as graphic locations.
Having read the file information and done some processing on it.
I want to sort it into alphabetical order for later outputting by letter.
For example all “A” file will be printed into part of a html table under “A”
“B” will go into another part of a html table etc.
I have manage to do this but (I know always a but) I’m sure that the way im doing it is no way the best solution.
As I end up having 26 arrays and 26 if else statements and lastly 26 output statement.
I have thought that maybe I could “join” each alphabetical list together as one string and then place it into one array for later outputting.
Before I embark on this I would welcome anybody suggestions and comments.
Regards,
Gareth
sub read_db_list { open (FILELIST, "<$filelistdb") or die "Sorry File list not available" +; foreach $fileinlist (<FILELIST>) { chomp($fileinlist); ($path,$file_type,$file_name,$file_image,$file_description) = +split(/:/,$fileinlist); $infoline = "<a href=\"$path/$file_name\"><img src=\"images/$ +file_image\" width=\"128\" height=\"128\" alt=\"$file_description\">< +/a><p>"; #### I now find what letter filename start with in order to assign it +to A-Z list ##### if ($file_name =~m/^A/i) { push(@arrayA,$infoline); } elsif ($file_name =~/^B/i) { push(@arrayB,$infoline); } ###### What I would like to know is there a better way other then doin +g the above if statements 26 time for each letter. Ending up with 26 +arrays? } }
In reply to Help to improving my code please? by spacey
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |