Ok, I finished the programming of a script that reads a text file and sorts it alphabeticaly, but i am doing something wrong. I have the text file set up like this:

A
D
F
E
G
C
D
G
D
E

Where A, D, F, E, G are in the same cat, so i have the script put them on one string. and so forth where every 5 are a group, and it only sorts the first word from each group.
It works so far, but when it resaves it to the file, it adds a space before and somethimes after on everyword. It didn't do this untill I implented the alphabetical sort. This is my code, can you please tell me what is wrong.
#!c:/perl/bin/perl print "Content-type: text/html\n\n"; use CGI; ####################################################### ## © Copyright 2002 All Rights Reserved ## ## Mr. Andrew Jackson ## ####################################################### ####################################################### ##This little bugger here takes the .txt database and## ##sorts it in alphabetical order from A to Z ## ####################################################### open(items, "itemdat.txt") or die "could not open file"; @list1 = <items>; close(items); $kn = 0; for ($nk = 0; $nk <= $#list1; $nk){ $item1 = @list1[$nk]; chomp($item1); $nk++; $item2 = @list1[$nk]; chomp($item2); $nk++; $item3 = @list1[$nk]; chomp($item3); $nk++; $item4 = @list1[$nk]; chomp($item4); $nk++; $item5 = @list1[$nk]; chomp($item5); $nk++; @list[$kn] = "$item1&$item2&$item3&$item4&$item5"; $kn++; } $nk = 0; foreach $list (@list){ local($item1, $item2, $item3, $item4 ,$item5) = split(/&/, $list) +; @list1[$nk] = "$item1 \n"; $nk++; @list1[$nk] = "$item2 \n"; $nk++; @list1[$nk] = "$item3 \n"; $nk++; @list1[$nk] = "$item4 \n"; $nk++; @list1[$nk] = "$item5 \n"; $nk++; } open(items, ">itemdat.txt"); print items "@list1"; close(items); #################################### ##This is the end of little bugger## #################################### print "<title>Diablo II Broth - Items</title><body bgcolor='black' tex +t='white'>"; open(items, "itemdat.txt") or die "could not open file"; @contetnsoffile = <items>; close(items); $nk = 0; print "<font style='font-size: 23; font-family: Tahoma; color: Blue'>< +center>The Items We Own as of Now<br><font style='font-size: 12; colo +r: red'>In the order entered into the database</font></center></font> +<p>&nbsp"; print "<center><table width='60%' border='0'>"; print "<td align='center'><b><font color='green'>Name</font></b></td>< +td align='center'><b><font color='green'>Status</font></b></td><td al +ign='center'><b><font color='green'>Type</font></b></td><td align='ce +nter'><b><font color='green'>Mods</font></b></td><td align='center'>< +b><font color='green'>Quanity</font></b></td><tr>"; $color = "red"; for ($nk = 0; $nk <= $#contetnsoffile; $nk){ print "<td width='40%' align='center'><font color='$color'>@ +contetnsoffile[$nk]</font></td>"; $nk++; print "<td width='15%' align='center'><font color='$color'>@ +contetnsoffile[$nk]</font></td>"; $nk++; print "<td width='15%' align='center'><font color='$color'>@ +contetnsoffile[$nk]</font></td>"; $nk++; print "<td width='25%' align='center'><font color='$color'>@ +contetnsoffile[$nk]</font></td>"; $nk++; print "<td width='5%' align='center'><font color='$color'>@c +ontetnsoffile[$nk]</font></td><tr>"; $nk++; if ($color eq red){ $color = "blue"; } else { $color = "red"; } } print "</table></center>";
Perl Monk, Andrew Jackson

In reply to Alphabetical order with .txt file by Jaxonn

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.