Interesting point. I use $data 8 times. Half as a boolean test (no de-reference) and half as a hash reference (to recover one or more values). I guess (and maybe I'm wrong about this) that it doesn't worth the benchmark...

Here is the complete function code:

sub inputBox{ # Don't uncomment, use @_ instead # my $action_url = shift; # $_[0] # my $msgid = shift; # $_[1] # my $action = shift; # $_[2] my $data = $_[3]; # oh, I needed this one, I wasn't able to use a ha +sh-slice from a hash-reference in one shot. <readmore> return qq{<form action="$_[0]" method="post">\n}. ($_[1]? qq{ <input type="hidden" name="message_id" value="$_[1]" />\n +}:''). qq{ <input type="hidden" name="action" value="$_[2]" /> <input type="hidden" name="commit" value="1" /> <table align="center" border="1" cellpadding="5" cellspacing="0"> <tr valign="middle" align="center" bgcolor="$color{TABLE_HEAD}"> <td colspan="2"> } .($_[2] eq 'edit'? "Edit Message #$_[1]" : 'Compose New Message' ). qq{ </td> </tr> <tr valign="middle" align="left" > <td> Author: </td> <td> }.( $_[2] eq 'edit'? q{ <input type="text" name="author" size=" +40" }. ( $data? qq{value="$data->{author}"} : &TWiki::Func::getWikiUserName +() ) . qq{ />} : &TWiki::Func::getWikiUserName() ) . q{ </td> </tr> <tr valign="middle" align="left"> <td>Due Date: </td> <td>} . &gen_date_selector( 'due', ( $data? @$data{'day','month' +,'year','hour','minute'} : (localtime)[5]+1900, (localtime)[4]+1, (lo +caltime)[3], 23, 59 ) ) . qq{ </td> </tr> <tr valign="middle" align="left"> <td>Message: </td> <td> <textarea rows="5" name="msg" cols="50">}.($data? $data->{msg} + : '' ).qq{</textarea> </td> </tr> <tr valign="middle" align="left"> <td> <input type="checkbox" name="dropped" value="Y" }.($data && $d +ata->{dropped} eq 'Y'? 'CHECKED':'' ).q{>&nbsp;Dropped. </td> <td align="right"> <input type="submit" name="change" value="Change Message"> </td> </tr> </table> </form> }; }
-- monsieur_champs

In reply to Re^2: Trying to optimize de-referenced hash slice without scope variables... by monsieur_champs
in thread Trying to optimize de-referenced hash slice without scope variables... by monsieur_champs

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.