Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I think that Version (2) and (1) do exactly the same thing.
Version 2 is easier to understand. And I think that it is as least as fast if not faster. If we are benchmarking things, then we need to to "apples to apples".
#!/usr/bin/perl -w use strict; use Data::Dumper; ## version 1.... my $num =0; my %h = map{$_, $num++}('A'..'Z','a'..'z'); print Dumper \%h; ## version 2... my %hash; foreach my $letter (('A'..'Z','a'..'z')) { $hash{$letter}++; } print Dumper \%hash; foreach (sort keys %h) { print "$_ OK\n" if $hash{$_}; }
$VAR1 = { 'S' => 18, 'a' => 26, 'T' => 19, 'N' => 13, 'K' => 10, 'd' => 29, 'Y' => 24, 'E' => 4, 'j' => 35, 'y' => 50, 'Z' => 25, 'u' => 46, 'k' => 36, 'g' => 32, 't' => 45, 'e' => 30, 'J' => 9, 'W' => 22, 'v' => 47, 's' => 44, 'B' => 1, 'H' => 7, 'c' => 28, 'q' => 42, 'b' => 27, 'D' => 3, 'I' => 8, 'G' => 6, 'z' => 51, 'U' => 20, 'w' => 48, 'F' => 5, 'r' => 43, 'x' => 49, 'V' => 21, 'Q' => 16, 'h' => 33, 'M' => 12, 'C' => 2, 'L' => 11, 'f' => 31, 'i' => 34, 'A' => 0, 'n' => 39, 'O' => 14, 'X' => 23, 'P' => 15, 'm' => 38, 'l' => 37, 'p' => 41, 'R' => 17, 'o' => 40 }; $VAR1 = { 'S' => 18, 'a' => 26, 'T' => 19, 'N' => 13, 'K' => 10, 'd' => 29, 'Y' => 24, 'E' => 4, 'j' => 35, 'y' => 50, 'Z' => 25, 'u' => 46, 'k' => 36, 'g' => 32, 't' => 45, 'e' => 30, 'J' => 9, 'W' => 22, 'v' => 47, 's' => 44, 'B' => 1, 'H' => 7, 'c' => 28, 'q' => 42, 'b' => 27, 'D' => 3, 'I' => 8, 'G' => 6, 'z' => 51, 'U' => 20, 'w' => 48, 'F' => 5, 'r' => 43, 'x' => 49, 'V' => 21, 'Q' => 16, 'h' => 33, 'M' => 12, 'C' => 2, 'L' => 11, 'f' => 31, 'i' => 34, 'A' => 0, 'n' => 39, 'O' => 14, 'X' => 23, 'P' => 15, 'm' => 38, 'l' => 37, 'p' => 41, 'R' => 17, 'o' => 40 }; A OK B OK C OK D OK E OK F OK G OK H OK I OK J OK K OK L OK M OK N OK O OK P OK Q OK R OK S OK T OK U OK V OK W OK X OK Y OK Z OK a OK b OK c OK d OK e OK f OK g OK h OK i OK j OK k OK l OK m OK n OK o OK p OK q OK r OK s OK t OK u OK v OK w OK x OK y OK z OK Process completed successfully

In reply to Re: Efficiency of map vs. more verbose basic/fundamental code by Marshall
in thread Efficiency of map vs. more verbose basic/fundamental code by marquezc329

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (6)
As of 2024-04-18 14:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found