Jeff Westman <[EMAIL PROTECTED]> wrote:
: 
: In my limited experience with perl, I've never had to use
: the 'map' command, even though I see it used all the time.
: It seems to just be a short-cut of other commands/keywords
: that I've used.
: 
: So, when do you HAVE to use 'map', when no other option
: makes sense?!

    You never *have* to use map. It is a shortcut and it
and it can both obfuscate code and make it easier to read.
It depends on when you use it. The Schwartzian Transform
(a sorting solution) is much more readable using map. It
also can reduce the number of variables an algorithm uses.


    Here's an example: map changes this

my @sales_figures = 1 .. 10;
foreach my $figure ( @sales_figures ) {
    $figure = sprintf "\$% 3s.00\n", $figure;
}


    To this:

@sales_figures = map { sprintf "\$% 3s.00\n", $_ } @sales_figures;

    Beauty is in the eye of the beholder.


HTH,

Charles K. Clarkson
-- 
Head Bottle Washer,
Clarkson Energy Homes, Inc.
Mobile Home Specialists
254 968-8328









-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to