Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
    1. eval { $some_hash{some_key} = ( expr or die ) };
    2. $_ = expr or $_ for $some_hash{some_key};
    • > eval { $some_hash{some_key} = ( expr or die ) };
      this would catch exceptions raised in expr .

      > $_ = expr or $_ for $some_hash{some_key};
      well, not many readers would quickly guess that we are assigning something in the hash here

      • My suggestions were actually tongue-in-cheek, particularly the eval-based one. I would never write code like that.

        But it occurs to me that you can just as well arrange the aliasing in #2 the other way around:

        $_ and $foo{bar} = $_ for $baz;

        Unlike my previous suggestion this also avoids the unnecessary assignment in case the expression is false. I might actually use this in real code, although I would probably not write it with if and a for construct rather than the for modifier.

        for ( expr ) { $foo{ba