in reply to A "harmless" alternative to 'map{}'?

How about wrapping it in a sub, thusly?

sub new_lamps_for_old (\@) { my $old; map { $old = $_; $_ = Lamp->new(); $old; } @{$_[0]}; }

The prototype is used to guarantee that the map acts on lvalues.

I have been known to propose placing map in void context when modifying its arguments, just to call attention to the fact. I didn't really mind losing on that proposal.

After Compline,
Zaxo

Replies are listed 'Best First'.
Re: Re: A "harmless" alternative to 'map{}'?
by Juerd (Abbot) on Sep 09, 2002 at 06:48 UTC

    The prototype is used to guarantee that the map acts on lvalues.

    No. Prototypes cannot provide any guarantee.

    - Yes, I reinvent wheels.
    - Spam: Visit eurotraQ.
    

      Prototypes cannot provide any guarantee.

      The \@ prototype guarantees barfing if the argument doesn't start with an @, though. And seeing that arrays tend to be lvalues...

      Am I missing anything?

      — Arien

        Prototypes can be circumvented using a & and are completely disregarded for object method calls.

        Makeshifts last the longest.