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

Re: [MacPerl] Commenting blocks of code



At 09:13 -0500 9/03/2000, Simply Hao wrote:

>> but I'll have to admit that i find it obscure.  Does this load the
>> entire file into ram?

>It loads all unique lines into the %s hash as keys.  Ack.  :)
>For each line (while (<>)), check whether the line was seen yet:
>    $s{$_}
>Unless it exists as a key (and printed already), print it:
>    print unless $s{$_}
>Then increment the hash entry (assume uninitialized means zeroish):
>    $s{$_}++
>So you see, it's not obscure at all - just concisely idiomatic.
>-Hao

NEAT! No need to pre-sort the file - it prints only the first occurrence of
a line. A large text file sucked into %s might overload memory but that's a
known risk. Beats my original design.
Thanks for the explanation.



# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org