Initial add of defaria.com
[clearscm.git] / defaria.com / blogs / Status / archives / 000677.html
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml" id="sixapart-standard">
4 <head>
5    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6    <meta name="generator" content="Movable Type 5.2.3" />
7
8    <link rel="stylesheet" href="http://defaria.com/blogs/Status/styles-site.css" type="text/css" />
9    <link rel="alternate" type="application/atom+xml" title="Atom" href="http://defaria.com/blogs/Status/atom.xml" />
10    <link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="http://defaria.com/blogs/Status/index.xml" />
11
12    <title>Status for Andrew DeFaria: ucmwb 1.2.3 release/Perl'isms</title>
13
14    <link rel="start" href="http://defaria.com/blogs/Status/" title="Home" />
15    <link rel="prev" href="http://defaria.com/blogs/Status/archives/000676.html" title="UCMWB su bug" />
16    <link rel="next" href="http://defaria.com/blogs/Status/archives/000678.html" title="comptree/libs" />
17
18    <!--
19 <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
20          xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/"
21          xmlns:dc="http://purl.org/dc/elements/1.1/">
22 <rdf:Description
23     rdf:about="http://defaria.com/blogs/Status/archives/000677.html"
24     trackback:ping="http://defaria.com/mt/mt-tb.cgi/64"
25     dc:title="ucmwb 1.2.3 release/Perl&apos;isms"
26     dc:identifier="http://defaria.com/blogs/Status/archives/000677.html"
27     dc:subject="General Dynamics"
28     dc:description=" Released ucmwb 1.2.3..."
29     dc:creator=""
30     dc:date="2007-09-14T12:51:03-06:00" />
31 </rdf:RDF>
32 -->
33
34
35    
36
37    <script type="text/javascript" src="http://defaria.com/blogs/Status/mt-site.js"></script>
38 </head>
39 <body class="layout-one-column" onload="individualArchivesOnLoad(commenter_name)">
40    <div id="container">
41       <div id="container-inner" class="pkg">
42
43          <div id="banner">
44             <div id="banner-inner" class="pkg">
45                <h1 id="banner-header"><a href="http://defaria.com/blogs/Status/" accesskey="1">Status for Andrew DeFaria</a></h1>
46                <h2 id="banner-description">Searchable status reports and work log</h2>
47             </div>
48          </div>
49
50          <div id="pagebody">
51             <div id="pagebody-inner" class="pkg">
52                <div id="alpha">
53                   <div id="alpha-inner" class="pkg">
54
55                      <p class="content-nav">
56                         <a href="http://defaria.com/blogs/Status/archives/000676.html">&laquo; UCMWB su bug</a> |
57                         <a href="http://defaria.com/blogs/Status/">Main</a>
58                         | <a href="http://defaria.com/blogs/Status/archives/000678.html">comptree/libs &raquo;</a>
59                      </p>
60
61                      <a id="a000677"></a>
62                      <div class="entry" id="entry-677">
63                         <h3 class="entry-header">ucmwb 1.2.3 release/Perl'isms</h3>
64                         <div class="entry-content">
65                            <div class="entry-body">
66                               <ul>
67   <li>Released ucmwb 1.2.3</li>
68 </ul>
69                            </div>
70                            <div id="more" class="entry-more">
71                               <h3>FindBin, Getopt::Long and Display.pm</h3>
72
73 <p>Here's how I typically use <a
74  href="http://search.cpan.org/%7Enwclark/perl-5.8.8/lib/FindBin.pm">FindBin</a>:</p>
75
76 <div class=code><pre>
77 use FindBin;
78 ...
79 use lib "$FindBin::Bin/../lib";
80 ...
81 sub Usage ($) {
82   my ($msg) = @_;
83
84   display "ERROR: $msg\n" if defined $msg;
85   display &lt;&lt;END;
86 Usage: $FindBin::Script [-usage] [-verbose] [-debug] [-exec]
87                 -from_view &lt;view&gt; -label &lt;label_name&gt;
88 ...
89 END
90 </pre></div>
91
92 <p>Also I tend to use Getopt::Long. It is extremely flexible. Options can be specified in the GNU long method as in --debug or just -debug. Additionally you can abbreviate as in -d IFF there is no other option that starts with "d". Options can have parameters (-file myfile.txt or -file=myfile.txt), set boolean (-verbose can set say $verbose), automatic negation (-verbose or -noverbose), even call subroutines directly!k Here's an example.</p>
93
94 <div class=code><pre>
95 use GetOpt::Long;
96 ...
97 my $execute     = 0;
98 my $from_view;  # e.g. p6258c_RAN_FDD_Doc_Bld1_int
99 my $branch;     # e.g. ran_fdd_release_build2_integration
100 my $label;      # e.g. RAN_FDD_RELEASE_BUILD1
101
102 GetOptions (
103   "usage"       =&gt; sub { Usage "" },
104   "verbose"     =&gt; sub { set_verbose },
105   "debug"       =&gt; sub { set_debug },
106   "exec!"       =&gt; \$execute,
107   "from_view=s" =&gt; \$from_view,
108   "branch=s"    =&gt; \$branch,
109   "label=s"     =&gt; \$label,
110 ) || Usage "Unknown parameter";
111 </pre></div>
112
113 <p>Some notes about the above:</p>
114
115 <ul>
116   <li>Usage is a subroutine (most people have one) that takes one parameter for an extra message to display first.</li>
117
118   <li>Eat your own dog food! I use my <a href="http://clearscm.com/php/cvs_man.php?file=lib/Display.pm">Display</a> module which has display routines for verbose and debug, etc. It also has $verbose and $debug variables and exports the set_verbose and set_debug methods.</li>
119
120   <li>The "exec!" is a negation. So -exec and -noexec apply and set $execute accordingly</li>
121
122   <li>All of "from_view", "branch" and "label" are simple name/value type parameters so -branch &lt;branchname&gt; sets $branch to &lt;branchname&gt;.</li>
123 </ul>
124
125 <p>A word on Display.pm:</p>
126
127 <p>I find that often people do the following:</p>
128
129
130 <div class=code><pre>
131 print "In myspecial_subroutine: File = $file\n" if $debug;
132 </pre></div>
133
134 <p>for debugging. To me it's always been a hassle to have to remember to include the "\b" and the "if $debug", etc. Granted that's not a lot. But how can I make it better?</p>
135
136 <p>My thought was to name the procedure debug and include the "\n" by default. People oughta quickly discern that:</p>
137
138 <div class=code><pre>
139 debug "In myspecial_subroutine: File = $file";
140 </pre></div>
141
142 <p>probably only happens when debugging.</p>
143
144 <p>Additionally I support routines like verbose, debug, error, warning
145 (from Display.pm).</p>
146                            </div>
147                         </div>
148                         <p class="entry-footer">
149                            <span class="post-footers">Posted by  on September 14, 2007 12:51 PM</span> <span class="separator">|</span> <a class="permalink" href="http://defaria.com/blogs/Status/archives/000677.html">Permalink</a>
150                         </p>
151                      </div>
152
153                      
154                      <div class="trackbacks">
155                         <h3 id="trackback" class="trackbacks-header">TrackBack</h3>
156                         <div id="trackbacks-info">
157                            <p>TrackBack URL for this entry:<br />http://defaria.com/mt/mt-tb.cgi/64</p>
158                         </div>
159                         <div class="trackbacks-content">
160                            
161                         </div>
162                      </div>
163                      
164
165                      
166                   </div>
167                </div>
168             </div>
169          </div>
170       </div>
171    </div>
172 </body>
173 </html>