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">
5 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6 <meta name="generator" content="Movable Type 5.2.3" />
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" />
12 <title>Status for Andrew DeFaria: ucmwb 1.2.3 release/Perl'isms</title>
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" />
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/">
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'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..."
30 dc:date="2007-09-14T12:51:03-06:00" />
37 <script type="text/javascript" src="http://defaria.com/blogs/Status/mt-site.js"></script>
39 <body class="layout-one-column" onload="individualArchivesOnLoad(commenter_name)">
41 <div id="container-inner" class="pkg">
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>
51 <div id="pagebody-inner" class="pkg">
53 <div id="alpha-inner" class="pkg">
55 <p class="content-nav">
56 <a href="http://defaria.com/blogs/Status/archives/000676.html">« 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 »</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">
67 <li>Released ucmwb 1.2.3</li>
70 <div id="more" class="entry-more">
71 <h3>FindBin, Getopt::Long and Display.pm</h3>
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>
79 use lib "$FindBin::Bin/../lib";
84 display "ERROR: $msg\n" if defined $msg;
86 Usage: $FindBin::Script [-usage] [-verbose] [-debug] [-exec]
87 -from_view <view> -label <label_name>
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>
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
103 "usage" => sub { Usage "" },
104 "verbose" => sub { set_verbose },
105 "debug" => sub { set_debug },
106 "exec!" => \$execute,
107 "from_view=s" => \$from_view,
108 "branch=s" => \$branch,
109 "label=s" => \$label,
110 ) || Usage "Unknown parameter";
113 <p>Some notes about the above:</p>
116 <li>Usage is a subroutine (most people have one) that takes one parameter for an extra message to display first.</li>
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>
120 <li>The "exec!" is a negation. So -exec and -noexec apply and set $execute accordingly</li>
122 <li>All of "from_view", "branch" and "label" are simple name/value type parameters so -branch <branchname> sets $branch to <branchname>.</li>
125 <p>A word on Display.pm:</p>
127 <p>I find that often people do the following:</p>
130 <div class=code><pre>
131 print "In myspecial_subroutine: File = $file\n" if $debug;
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>
136 <p>My thought was to name the procedure debug and include the "\n" by default. People oughta quickly discern that:</p>
138 <div class=code><pre>
139 debug "In myspecial_subroutine: File = $file";
142 <p>probably only happens when debugging.</p>
144 <p>Additionally I support routines like verbose, debug, error, warning
145 (from Display.pm).</p>
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>
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>
159 <div class="trackbacks-content">