Initial add of defaria.com
[clearscm.git] / defaria.com / blogs / Status / archives / 000492.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: BinMerge Module & Perl Issues</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/000491.html" title="Stripmime/Cleardiffmrg/CharacterSetValidation" />
16    <link rel="next" href="http://defaria.com/blogs/Status/archives/000493.html" title="Bin Merge updates/GNATS: Another word for &quot;bug&quot;! :-(" />
17
18    
19
20    
21
22    <script type="text/javascript" src="http://defaria.com/blogs/Status/mt-site.js"></script>
23 </head>
24 <body class="layout-one-column" onload="individualArchivesOnLoad(commenter_name)">
25    <div id="container">
26       <div id="container-inner" class="pkg">
27
28          <div id="banner">
29             <div id="banner-inner" class="pkg">
30                <h1 id="banner-header"><a href="http://defaria.com/blogs/Status/" accesskey="1">Status for Andrew DeFaria</a></h1>
31                <h2 id="banner-description">Searchable status reports and work log</h2>
32             </div>
33          </div>
34
35          <div id="pagebody">
36             <div id="pagebody-inner" class="pkg">
37                <div id="alpha">
38                   <div id="alpha-inner" class="pkg">
39
40                      <p class="content-nav">
41                         <a href="http://defaria.com/blogs/Status/archives/000491.html">&laquo; Stripmime/Cleardiffmrg/CharacterSetValidation</a> |
42                         <a href="http://defaria.com/blogs/Status/">Main</a>
43                         | <a href="http://defaria.com/blogs/Status/archives/000493.html">Bin Merge updates/GNATS: Another word for "bug"! :-( &raquo;</a>
44                      </p>
45
46                      <a id="a000492"></a>
47                      <div class="entry" id="entry-492">
48                         <h3 class="entry-header">BinMerge Module & Perl Issues</h3>
49                         <div class="entry-content">
50                            <div class="entry-body">
51                               <ul>
52   <li>Changed bin_merge to be a module so that it easier to call from UCMCustom</li>
53
54   <li>Integrated new BinMerge.pm module into the UCMCustom</li>
55
56   <li>Added fix to use "\" in get_vob_str</li>
57
58   <li>Changed UCMCustom to use strict and warnings(we should always use these)</li>
59
60   <li>Changed UCMCustom to use use instead of require</li>
61
62   <li>Hunted down bug where UCMCustom undef's $/ (Bad UCMCustom!! Bad!)</lI>
63 </ul>
64                            </div>
65                            <div id="more" class="entry-more">
66                               <h2>BinMerge Module</h2>
67
68 <p>I decided to change bin_merge into a module (BinMerge) and use it in UCMCustom. I was having problems trying to start the bin_merge process and getting it going in a pipe so the output from verbose could give the user feed back. For some reason bin_merge has to exit before any output was returned. Might have been because of the $/ thing described below (Bad UCMCustom, bad!)</p>
69
70 <h2>Using strict</h2>
71
72 <p>I've been taught that both use strict and use warnings should always be used when coding Perl. These diagnoistic routines are helpful in catching some common Perl mistakes that are otherwise much more difficult to debug. In fact, in implementing this I found a few potential bugs that I also corrected.</p>
73
74 <blockquote>
75 <p><b>Note:</b> Some version of Perl do not have use warnings. Instead specify -w on the #! line.</p>
76 </blockquote>
77
78 <h2>Use vs Require</h2>
79
80 <p>Require is old hat. Use is the new require! From Perldoc's <a href="http://perldoc.perl.org/perlfaq8.html#What%27s-the-difference-between-require-and-use%3F">What's the difference between require and use?</a>:</p>
81
82 <blockquote>
83   <h2>What's the difference between require and use?</h2>
84
85   <p>Perl offers several different ways to include code from one file into another. Here are the deltas between the various inclusion constructs:</p>
86
87   <ol>
88     <li> do $file is like eval `cat $file`, except the former</li>
89       <ol>
90         <li>searches @INC and updates %INC.</li>
91
92         <li>bequeaths an *unrelated* lexical scope on the eval'ed code.</li>
93       </ol>
94
95     <li>require $file is like do $file, except the former</li>
96       <ol>
97         <li>checks for redundant loading, skipping already loaded files.</li>
98
99         <li>raises an exception on failure to find, compile, or execute $file.</li>
100       </ol>
101
102     <li>require Module is like require "Module.pm", except the former</li>
103       <ol>
104         <li>translates each "::" into your system's directory separator.</li>
105
106         <li>primes the parser to disambiguate class Module as an indirect object.</li>
107       </ol>
108
109     <li>use Module is like require Module, except the former</li>
110       <ol>
111         <li>loads the module at compile time, not run-time.</li>
112
113         <li>imports symbols and semantics from that package to the current one.</li>
114       </ol>
115   </ol>
116 </blockquote>
117
118 <p>Note that becuase use loads the module at compile time one need to arrange for the @INC array to have any paths needed for use to succeed (IOW user written modules). In order to accomplish this one need to seed the @INC arrray in a BEGIN block as BEGIN blocks are executed before use is expanded,</p>
119
120 <h2>$/ Bug</h2>
121
122 <p>From Perldoc's <a href="http://perldoc.perl.org/perlvar.html">Perlvar</a>:</p>
123
124 <blockquote>
125   <p>You should be very careful when modifying the default values of most special variables described in this document. In most cases you want to localize these variables before changing them, since if you don't, the change may affect other modules which rely on the default values of the special variables that you have changed. This is one of the correct ways to read the whole file at once:</p>
126
127   <div class="code"><pre>
128   open my $fh, "foo" or die $!;
129   local $/; # enable localized slurp mode
130   my $content = <$fh>;
131   close $fh;
132   </pre></div>
133
134   <p>But the following code is quite bad:</p>
135
136   <div class="code"><pre>
137   open my $fh, "foo" or die $!;
138   undef $/; # enable slurp mode
139   my $content = <$fh>;
140   close $fh;
141   </pre></div>
142
143   <p>since some other module, may want to read data from some file in the default "line mode", so if the code we have just presented has been executed, the global value of $/ is now changed for any other code running inside the same Perl interpreter.</p>
144 </blockquote>
145                            </div>
146                         </div>
147                         <p class="entry-footer">
148                            <span class="post-footers">Posted by  on December  7, 2005  5:44 PM</span> <span class="separator">|</span> <a class="permalink" href="http://defaria.com/blogs/Status/archives/000492.html">Permalink</a>
149                         </p>
150                      </div>
151
152                      
153
154                      
155                   </div>
156                </div>
157             </div>
158          </div>
159       </div>
160    </div>
161 </body>
162 </html>