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

Re: [MacPerl] Commenting blocks of code



> while ( <> )
> {
> print unless $s{$_}++
> }
>
> 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

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