Initial add of defaria.com
[clearscm.git] / defaria.com / blogs / Status / archives / 000516.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: Perl test</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/000517.html" title="Clearcase Merging/CQ Time Stamp problem/CQ Help problem" />
16    <link rel="next" href="http://defaria.com/blogs/Status/archives/000518.html" title="PQA CDO.Message" />
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/000517.html">&laquo; Clearcase Merging/CQ Time Stamp problem/CQ Help problem</a> |
42                         <a href="http://defaria.com/blogs/Status/">Main</a>
43                         | <a href="http://defaria.com/blogs/Status/archives/000518.html">PQA CDO.Message &raquo;</a>
44                      </p>
45
46                      <a id="a000516"></a>
47                      <div class="entry" id="entry-516">
48                         <h3 class="entry-header">Perl test</h3>
49                         <div class="entry-content">
50                            <div class="entry-body">
51                               <ul>
52   <li>Ray wanted an easy/medium/hard Perl test</li>
53 </ul>
54                            </div>
55                            <div id="more" class="entry-more">
56                               <h2>Perl Test</h2>
57
58 <h3>Easy</h3>
59 <ol>
60   <li>What does Perl stand for?</li>
61
62 <p><font color="red">Practical Extraction and Reporting Language</font></p>
63
64   <li>What basic datatypes does Perl support?</li>
65
66 <p><font color="red">Scalar, Array, Hash, Typeglob</font></p>
67
68   <li>What does the following do:</li>
69
70 <div class="code"><pre>
71 my @output = &lt;STDIN&gt;;
72
73 foreach (@output) {
74   print "$_\n" if /\d+/;
75 }
76 </pre></div>
77
78 <p><font color="red">Echoes lines that have numbers in them)</font></p>
79
80 </ol>
81
82 <h3>Medium</h3>
83
84 <ol>
85   <li>What is <tt>use strict</tt> and why is it important to use?</li>
86
87 <p><font color="red">Strict requires that variable references are scoped - e.g. my $var)</font></p>
88
89   <li>What does the following code do:</li>
90
91 <div class="code"><pre>
92 sub d {
93   my %p = @_;
94
95   print "\np:\n";
96
97   foreach (sort (keys (%p))) {
98     if (/password/) {
99       print "$_: &lt;password&gt;\n";
100     } else {
101       print "$_: ${p {$_}}\n";
102     } # if
103   } # foreach
104 } # d
105 </pre></div>
106
107 <p><font color="red">Displays the contents of the passed in hash %p substituting "&lt;password&gt;" if the hash happens to have a key of password</font></p>
108
109   <li>What do you do to enable Perl to find user written modules?</li>
110
111 <p><font color="red">You need to modify the @INC array to include the path to your modules)</font></p>
112 </ol>
113
114 <h3>Hard</h3>
115
116 <ol>
117   <li>What is the difference between <tt>require</tt> and <tt>use</tt>?</li>
118  
119 <p><font color="red">See <a href="/blogs/Status/archives/000492.html">this article</a> for the answer</font></p>
120
121   <li>What is a better way to do the following and why:</li>
122
123 <div class="code"><pre>
124 undef $/;
125 </pre></div>
126
127 <p><font color="red">See <a href="/blogs/Status/archives/000492.html">this article</a>) for the answer</font></p>
128
129   <li>What does the following print out when executed:</li>
130
131 <div class="code"><pre>
132 sub foo {
133   my ($x, $y) = @_;
134
135   my @z = `$x 2&gt;&amp;1`; chomp @z;
136   my $s = $?;
137
138   if ($s ne 0) {
139     if (defined $y) {
140       print "$_\n" foreach (@z);
141     }
142   }
143
144   return ($y, @z);
145 } # foo
146
147 my @a;
148 my $c="ls /temp";
149 my $d;
150
151 ($d, @a) = foo $c;
152 print "Worked!\n" if !$d;
153 </pre></div>
154
155 <p><font color="red">(It will output:</p>
156
157 <div class="code"><pre>
158 Worked!
159 </pre></div>
160
161 <p>Yet nothing really worked at all! Key issues are:</p>
162
163 <ul>
164     <li>Passing parameters to subroutines. Two parameters are passed in</li>
165
166     <li>Parameter return: Two parameters are returned</li>
167
168     <li>Evaluation of parameters: $y in foo is not passed in thus the print... foreach doesn't execute></li>
169
170     <li>Evaluation of true/false: foo returns $y which is errno,
171 which is not 0 thus not true but the !$d evaluates to true and the
172 print "Worked!\n" gets executed.</li>
173 </font></ul>
174 </ol>
175
176                            </div>
177                         </div>
178                         <p class="entry-footer">
179                            <span class="post-footers">Posted by  on January 13, 2006 11:59 AM</span> <span class="separator">|</span> <a class="permalink" href="http://defaria.com/blogs/Status/archives/000516.html">Permalink</a>
180                         </p>
181                      </div>
182
183                      
184
185                      
186                   </div>
187                </div>
188             </div>
189          </div>
190       </div>
191    </div>
192 </body>
193 </html>