<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:tahoma, 'new york', times, serif;font-size:12pt">instead of using map, you could use a hash slice:<div><br></div><div><span class="Apple-style-span" style="font-family: 'Times New Roman'; font-size: 13px; ">my ($fee, $fi, $fo) = @{ $fropper || $gropper }{ qw/fee fi fo/ };</span></div><div><font class="Apple-style-span" face="'Times New Roman'" size="3"><span class="Apple-style-span" style="font-size: 13px;"><br></span></font><div> </div>---<br>Mark Mertel<br>206.441.4663<br>mark.mertel@yahoo.com<br><span><a target="_blank" href="http://www.linkedin.com/in/markmertel">http://www.linkedin.com/in/markmertel</a></span><br><span><a target="_blank" href="http://www.seattlejobs.com/13147468">http://www.seattlejobs.com/13147468</a></span><div><br></div><div style="font-family:tahoma, new york, times, serif;font-size:12pt"><br><div style="font-family:times
 new roman, new york, times, serif;font-size:12pt"><font size="2" face="Tahoma"><hr size="1"><b><span style="font-weight: bold;">From:</span></b> "seasprocket@gmail.com" &lt;seasprocket@gmail.com><br><b><span style="font-weight: bold;">To:</span></b> spug-list@pm.org<br><b><span style="font-weight: bold;">Sent:</span></b> Thursday, April 9, 2009 8:52:22 PM<br><b><span style="font-weight: bold;">Subject:</span></b> SPUG: Interesting bug using 'map'<br></font><br>
I ran into a bug tonight using 'map' which taught me something about map and raised a further question:<br><br>   my ($fee, $fi, $fo) =<br>       map {$fropper ? $fropper->$_ : $glopper->$_}<br>           qw/fee fi fo/;<br>

<br>The bug arises bc fropper and glopper are not guaranteed to have return values for fee/fi/fo, and bc map evaluates BLOCK in LIST context. So if fee or fi is undefined, you get an empty list which collapses in the final result. Then fi or fo can get assigned to the wrong variable.<br>

<br>Here's my question, I can prevent it this way (by ORing with an empty string):<br><br>   my ($fee, $fi, $fo) =<br>       map {$fropper ? $fropper->$_ || '' : $glopper->$_ || ''}<br>           qw/fee fi fo/;<br>

<br>But that's ugly -- is there a cleaner way to avoid this problem?<br><br><br clear="all"><br>-- <br>==========================<br><span>2People citizen's network for climate action: <a target="_blank" href="http://www.2people.org">http://www.2people.org</a></span><br>

<br><span>Greater Seattle Climate Dialogues: <a target="_blank" href="http://www.climatedialogues.org">http://www.climatedialogues.org</a></span><br>The Great Warming coalition<br>==========================<br>
</div></div><div style="position:fixed"></div></div></div><br>

      </body></html>