Your script is very elegant, shorter and functionally equivalent.
However, this simplicity comes at a price. The overhead of a second hash to eliminate duplicates is a heavy load on performance, especially after adding "use strict" and "-w" on top.
I compared the execution times on a 102_759 words dictionary.
$ time perl gmax_anagram.pl < words |wc
4.26user 0.07system 0:04.32elapsed
6427 14802 107910
$ time perl merlyn_anagram.pl < words |wc
6.35user 0.10system 0:06.45elapsed
6427 14802 107910
(after adding use strict and -w)
$ time perl merlyn_anagram.pl < words |wc
7.44user 0.12system 0:07.55elapsed
6427 14802 107910
Anyway, this approach is one more thing to know, if I want to privilege a shorter script in favor of a faster one.
Thanks.
_ _ _ _
(_|| | |(_|><
_|
-
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.
|