Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

comment on

( [id://3333] : superdoc . print w/replies, xml ) Need Help??
Performance is different, and return hash ref has a much better performance. Try the following test: (I tried 1000 by 200, return hash cost 20 secs, when return ref only cost 13 secs. Well... you can see how slow my PC is.)

use strict; sub return_hash { my %hash; for (0..shift) { $hash{$_} = $_; } return %hash; } sub return_hash_ref { my %hash; for (0..shift) { $hash{$_} = $_; } return \%hash; } my $ti = time(); for (0..$ARGV[1]) { my %hash = return_hash($ARGV[0]); } print "return hash takes: ", time() - $ti, " secs\n"; $ti = time(); for (0..$ARGV[1]) { my $hash = return_hash_ref($ARGV[0]); } print "return hash REF takes: ", time() - $ti, " secs\n";

In reply to Re: Subroutines: Returning a hash vs. hash reference by pg
in thread Subroutines: Returning a hash vs. hash reference by mt2k

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.