[Top][All Lists]

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

Re: Fix for PR 164 (?)

From: Russ Allbery
Subject: Re: Fix for PR 164 (?)
Date: 05 May 2001 18:15:45 -0700
User-agent: Gnus/5.0807 (Gnus v5.8.7) XEmacs/21.1 (Channel Islands)

Tom Tromey <address@hidden> writes:

> +    # Make a hash holding all the values from $WHEN.
> +    my (%cond_vals);
> +    grep ($cond_vals{$_} = 1, split (' ', $when));

It's generally considered poor Perl coding style to use grep for its side
effects alone without checking the return value.  It can make people blink
a few times as they try to figure out why grep is being used.  :)  I'd
write that instead as:

    my %cond_vals = map { $_ => 1 } split (' ', $when);

which is the Lisp-ish way to do it.  A more C-like and equally valid way
of writing it is:

    my %cond_vals;
    for (split (' ', $when)) {
        $cond_vals{$_} = 1;

(s/for/foreach/ if you prefer it).

Russ Allbery (address@hidden)             <>

reply via email to

[Prev in Thread] Current Thread [Next in Thread]