perlmeditation
japhy
With the onslaught of golf meditations recently (of which I shall soon be posting one -- fear not!), I'm posting a set of reminders that you may be wont to take heed of, ere you post again!
<ul>
<li> if you use a regex, be sure <tt>.</tt> can match a newline, by using the <tt>/s</tt> modifier to the regex
<li> <tt>pop</tt> is two characters less than <tt>shift</tt>
<li> assign to <tt>@_</tt> and <tt>$_</tt> if you can -- it saves a <tt>my</tt> declaration (if you're stingy), and allows operations like regexes and <tt>pop</tt> to work without an argument
<li> screw <tt>$1</tt> and the like, and use <tt>$&</tt> and its friends instead
<li> <tt>map()</tt> is probably a useful tool to master for golf
<li> leave out semicolons wherever possible
<li> don't explicitly <tt>return</tt> unless you must
<li> doing <tt>.$/</tt> is shorter than <tt>."\n"</tt> -- same for <tt>.$"</tt> vs. <tt>." "</tt>
<li> <tt>{...;redo}</tt> is shorter than <tt>while(1){...}</tt>
<li> <tt>{...;$x&&redo}</tt> is shorter than <tt>while($x){...}</tt>
<li> use <tt>||</tt> and <tt>&&</tt>
</ul>
<br><br>
<tt><font color="#0000ff">japhy</font></tt> --
<a href="/index.pl?node=japhy&lastnode_id=1072">Perl and Regex Hacker</a>