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

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

Thread Previous | Thread Next
Dave Mitchell
July 20, 2016 14:44
Re: [perl #128678] Wish: 'hard assignment' operator
Message ID:
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,

    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 Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About