[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] System Calls



You ask if there's another way to:
        system("sort badsummary > baddup;  uniq < baddup > badfinal");

The answer, of course, is that in Perl there is ALWAYS another way.

I'm pretty sure this is suboptimal, but I too would like to know a
nice way to do that.  Here is my untested, composed on the spot, way:

open( BAD, "<badsummary");
open( FIN, ">badfinal");
while(<BAD>) {chomp; $bad{$_} = ''}
foreach (sort keys %bad) {print FIN}

This actually does the uniq first since storing a second value
under the same key-string in a hash has no observable effect.
For this reason, it is not as easy to generate the baddup file,
but I'm wagering that you have no real use for it anyway.
I would hope there is actually a better way to sort since I'm
given to understand that hashes use memory profligately.

Incidentally, I have a commented Perl script referenced on my
home page, below.  Let me know if there are others on the Web,
or send me some to put on the Web if that's any easier than
putting it up yourself.

Dick Karpinski   dick@itsa.ucsf.edu   http://www.ucsf.edu/~dick