Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Re: Alphabetical order with .txt file

by lemming (Priest)
on Apr 17, 2002 at 01:21 UTC ( #159694=note: print w/replies, xml ) Need Help??

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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://159694]
[Tanktalus]: I think I'm "out there" somewhere. I sure don't feel like I'm "here" right now. :S
Discipulus psylocibina party?
[Discipulus]: listen monks: do you think is possible to realize here at pm some kind of collaborative works? beyond ask & answer, i mean
[Tanktalus]: isn't that what github, sourceforge, gitlabs, etc., are for?

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (8)
As of 2017-09-22 21:09 GMT
Find Nodes?
    Voting Booth?
    During the recent solar eclipse, I:

    Results (269 votes). Check out past polls.