in reply to Array-ize a function

You find

print a(\&do_something)->(1 .. 5);

preferable to:

print map do_something( $_ ) , 1 .. 5;

? or better still

sub do_something { map{ $_ * 2 } @_ } print do_something 10; 20 print do_something 1..5; 2 4 6 8 10

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco.
Rule 1 has a caveat! -- Who broke the cabal?

Replies are listed 'Best First'.
Re^2: Array-ize a function
by polettix (Vicar) on Mar 18, 2005 at 15:55 UTC
    Well... no. Actually, I had multiple goals when I wrote the snippet.

    When I was on my scooter going back home, I simply thought about simply using map to do the job. Clean and straightforward, as in your first suggestion.

    Then, I was wondering about a scenario in which I would re-use already written functions without touching them. This obviously kicks the last proposal out, which modifies do_something, even if I've to admit that it's quite an elegant approach.

    By the time I came home, I was obsessed by minimising typing (I like these variations on the theme...), so I ended up with that solution. Moreover, I get a pretty obfuscated code with my solution - don't you agree? :) The better I was able to do is to lower typing overhead down to 8 chars.

    -- Don't fool yourself.