[mplspm]: In a sorted list [better]

Ken Williams ken at mathforum.org
Mon Mar 25 17:23:34 CST 2002


Hey Josh,

Some pointers:


On Saturday, March 23, 2002, at 05:57 AM, Josh Aas wrote:
> #!/usr/bin/perl
>
> print "Loading file...\n";
>
> open (DATA, "/Users/Josh/Big_List.txt") || &CgiDie ("Cannot open
> wordlist.");
> my @data = <DATA>;
> close (DATA);
>
> print "Loading file done.\n";
>
> print "Cleaning...\n";
> foreach (@data) {
>     chomp;
> }
> print "Done cleaning.\n";

Better to just do everything at once:

-------------------------------------------
print "Loading file...\n";

open (DATA, "/Users/Josh/Big_List.txt") || &CgiDie ("Cannot open
wordlist.");
chomp(my @data = sort <DATA>);
close (DATA);

print "Loading file, cleaning, & sorting done.\n";
-------------------------------------------

> $wordcount = scalar(@data);
> print "There are ";
> print $wordcount;
> print " words in the file.\n";

You can just do:

    print "There are $wordcount words in the file.\n";

Oops - I was going to give some more pointers, but I have to go.

  -Ken



--------------------------------------------------
Minneapolis Perl Mongers mailing list

To unsubscribe, send mail to majordomo at pm.org
with "unsubscribe mpls" in the body of the message.



More information about the Mpls-pm mailing list