On Fri, Apr 10, 2009 at 11:30 AM, Mark Mertel <span dir="ltr">&lt;<a href="mailto:mark.mertel@yahoo.com">mark.mertel@yahoo.com</a>&gt;</span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div><div style="font-family: tahoma,&#39;new york&#39;,times,serif; font-size: 12pt;">instead of using map, you could use a hash slice:<div><br></div><div><span style="font-family: &#39;Times New Roman&#39;; font-size: 13px;">my ($fee, $fi, $fo) = @{ $fropper || $gropper }{ qw/fee fi fo/ };</span></div>
<div><font size="3" face="&#39;Times New Roman&#39;"><span style="font-size: 13px;"></span></font></div></div></div></blockquote><div><br>Not exactly.  I thought of this as well and it seems you might get a tiny performance gain doing it this way since the existence of $fropper is only evaluated once.<br>
<br>Looking more closely I realized that the OP is doing method calls &quot;$fropper-&gt;$_&quot; instead of hash lookups &quot;$fropper-&gt;{$_}&quot;.  A slice in this case would only work if you had these objects tied to a
hash class that overloaded FETCH with a method call.  I imagine that
would incur a performance penalty.<br><br>The fact that these are method calls is the reason that Phil is running into the scalar vs. list context issue.  A hash look-up have this problem.<br><br>If I knew there were a ton of methods to be called I might do this:<br>
<br>my $opper = $fropper || $glopper;<br><br>my ($fee, $fi, $fo, ...) = map {scalar($opper-&gt;$_)} qw/fee fi fo .../;<br><br>Of course, if calling any of these methods on $glopper has the side effect of changing the existence of $fropper then this won&#39;t give you the same result as in Phil&#39;s example.<br>
<br>-- <br>Ben<br></div></div>