Hello to all,
Would somebody be kind enough to pick and poke at this code?

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.