From what I can see, they do the same thing with the easier to understand map{$_*5} @vals being very, very slightly slower as far as execution time. Doesn't appear to be enough slower to sacrifice the understandability.
#!/usr/bin/perl -w use strict; my @values = qw(1 2 3 4 5 6 7 8 9 10 11 12 13 14); print "Just to show that these do the same\n"; my @vals1 = map($_*5, @values); print "@vals1\n"; my @vals2 = map{$_*5} @values; print "@vals2\n"; #prints: #Just to show that these do the same #5 10 15 20 25 30 35 40 45 50 55 60 65 70 #5 10 15 20 25 30 35 40 45 50 55 60 65 70 use Benchmark; timethese (1000000, { paren => q{ my @values = qw(1 2 3 4 5 6 7 8 9 10 11 12 13 14); my @vals = map($_*5, @values); }, block => q{ my @values = qw(1 2 3 4 5 6 7 8 9 10 11 12 13 14); my @vals = map{$_*5} @values; }, } ); __END__ Just to show that these do the same 5 10 15 20 25 30 35 40 45 50 55 60 65 70 5 10 15 20 25 30 35 40 45 50 55 60 65 70 Benchmark: timing 1000000 iterations of block, paren... block: 20 wallclock secs (19.38 usr + 0.00 sys = 19.38 CPU) @ 51612.90/s (n=1000000) paren: 20 wallclock secs (19.30 usr + 0.00 sys = 19.30 CPU) @ 51821.53/s (n=1000000) Just to show that these do the same 5 10 15 20 25 30 35 40 45 50 55 60 65 70 5 10 15 20 25 30 35 40 45 50 55 60 65 70 Benchmark: timing 1000000 iterations of block, paren... block: 20 wallclock secs (19.44 usr + 0.00 sys = 19.44 CPU) @ 51445.62/s (n=1000000) paren: 20 wallclock secs (19.39 usr + 0.00 sys = 19.39 CPU) @ 51570.32/s (n=1000000)

In reply to Re: syntax of map operator by Marshall
in thread syntax of map operator by sman

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.