<?xml version="1.0" encoding="windows-1252"?>
<node id="214904" title="Re: Confessions of an Initiate: a first Perl program" created="2002-11-21 15:33:04" updated="2005-07-27 05:19:20">
<type id="11">
note</type>
<author id="34691">
Chmrr</author>
<data>
<field name="doctext">
&lt;p&gt;I'd second most of the suggestions that [Thesus] and [fruiture] offered.  Furthermore, I'd comment that as this is a purely linear script, there are few advantages to using subroutines other than the visual partitioning.  The downside is that it promotes either the use of globals, as you did, or rediculous amounts of variable passing.  And globals, as we all know "are always bad."&lt;sup style="font-size: 50%"&gt;{1}&lt;/sup&gt;  As such, were I writing this, I would do away with the subroutines and just deliniate the sections with comments.&lt;/p&gt;
&lt;p&gt;Also, you hard-code the values of the popup box -- why, when you can get at them far easier by using &lt;code&gt;keys %all_quotas&lt;/code&gt;?  This will also prevent errors caused by typos, as well as allowing for expansion if you add more lines of data.  The same concept applies to the default value of the popup.&lt;/p&gt;
&lt;p&gt;Another tip is that most of the lines of &lt;code&gt;process_query&lt;/code&gt; boil down to:&lt;/p&gt;
&lt;code&gt;sub process_query {
  $period = $query-&gt;param('period') || (keys %all_quotas)[0];
  print_table;
}&lt;/code&gt;
&lt;p&gt;Note the use of the || operator to set a default -- that's one of its primary uses.  Lastly, the gigantic paragraph that you put in quotes looks ripe for being a HERE document.&lt;/p&gt;
&lt;p&gt;You can see the agglomeration of the changes [http://chmrr.net/~chmrr/test.txt|here], and the result [http://chmrr.net/~chmrr/test.pl|here].  Ignore how I removed your __DATA__ section -- I had to do so because they don't play nice with mod_perl.  It is an excellent and appropriate use of __DATA__, but not one which works with mod_perl, unfortunatly.&lt;/p&gt;
&lt;p&gt;&lt;i&gt;{1}&lt;/i&gt; I hate generalizations like this.  But in this case, it's usually good advice.  There are times to use 'em, but here we don't need or want 'em.&lt;/p&gt;
&lt;p&gt;perl -pe '"I lo*`+$^X$\"$]!$/"=~m%(.*)%s;$_=$1;y^`+*^e v^#$&amp;V"+@( NO CARRIER'&lt;/p&gt;</field>
<field name="root_node">
214868</field>
<field name="parent_node">
214868</field>
</data>
</node>
