develooper Front page | perl.perl5.porters | Postings from July 2016

Re: [perl #128678] Wish: 'hard assignment' operator

Thread Previous | Thread Next
From:
Dave Mitchell
Date:
July 20, 2016 14:44
Subject:
Re: [perl #128678] Wish: 'hard assignment' operator
Message ID:
20160720144417.GP3477@iabyn.com
On Wed, Jul 20, 2016 at 06:46:29AM -0700, Ed Avis wrote:
>    foreach my $i (@items) {
>        $score{$i} := get_score($i);
>    }
> 
>    $x := $y;
> 
> The addition of the // operator to the language simplified a lot of
> code.  Things which needed two statements, or some careful dance with
> 'for', can now be written in a single statement which does the desired
> error check with only a couple of extra keystrokes.  I believe that a
> hard-assignment operator would be a similarly useful 'Huffman coding'.

For the cases where it is an error to assign to a non-undef lvalue,
I would imagine that normally you'd want a specific error message,
e.g.

    for (@flags) {
        die "duplicate flag $_ found in $config_file" if $config{$_};
        $config{$_} = 1;
    }

So I would expect a hard-assignment operator which just prints a generic
error message to have a relatively small application.

-- 
Little fly, thy summer's play my thoughtless hand
has terminated with extreme prejudice.
        (with apologies to William Blake)

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About