in reply to Alphabetical order with .txt file
Like grep says: use strict; use warnings;
That won't catch your problem though. You're adding a space with @list1[$nk] = "$item1 \n";. Try dropping the space before the newline.
Other concerns:
- @list1[$nk] is better written as $list1[$nk] ; Though just until Perl 6
- You currently read the file
Then sort (though it's not shown)
write the file
read it
and then display it - Try reading it
sorting it
displaying it and writing it at the same time - IIRC, $#list1 notation is being dropped. Just go ahead and use @list1 for # of elements. scalar @list1 is you need to.
- Another version of your code is in my pad
I'll leave that there for your review for now
Update: boo has an excellent point. I just glossed by that point.
|
---|
In Section
Seekers of Perl Wisdom