perlmeditation
neilh
I have been coding in Perl for about 7 years now. However, I am not a programmer, so I always thought I was pretty good. <p>
Once I was actually employed to write Perl, and spent three months developing a replacement for Crystal Reports using [cpan://GD::Graph] and [cpan://CGI]. The package eventually went on to make the company a lot of money as part of a larger product, but I had already left by that stage, so didn't reap the rewards.<p>
Prior to this year, I was employed as a DBA, and rather than writing SQL, I wrote everything using the most excellent [cpan://DBI] and [cpan://DBD::Oracle]. I left behind a lot of code for my replacement, and I heard the other day that he had rewritten eveything in ksh and deleted my work.<p>
As some of you know, for the last few months I have been working on a programme to synchronize the various directory servers we have here - Active Directory with Exchange, Sun One Directory Server, Oracle Internet Directory and the payroll system - using, among other things: [cpan://Net::LDAP]. This is the project that led me to the Monastery 12 weeks ago today.<br>
About two weeks ago, I finally finished phase one of this project and am now taking a much anticipated break from LDAP. <p>
<readmore>
The first thing I was told was that few people would help me until I learnt to <code>use strict;</code>. I took this advice to heart, and indeed within a few days I wrote everything using strictures.<br>
From there the whole world of lexical scope was opened to me. <br>
Within one week of joining the Monastery I started using subroutines. I was pretty proud of myself. I looked over the code that I had written and realised that a lot of it was repetitous, so I created a package of my own for all the stuff that I kept using, and just called it with <code>use lib '/path/to/new-package';</code>.<p>
The best package that I have learnt to use is [cpan://Tie::File]. This is my all time favourite. In the old days (ie about 4 weeks ago) in order to increment a sequence in a file, I used to do something like:<p>
<code>
open (FILE, "<file.txt");
my @file=<FILE>;
close FILE;
my $file[0]=$file[0] + 1;
open (FILE, ">file.txt");
print FILE "$file[0]\n";
close FILE;
</code>
Now, of course, I do the much better:<p>
<code>
tie my @file, 'Tie::File', 'file.txt';
$file[0]=$file[0] + 1;
untie @file;
</code>
As I look over my directory where the last three month's work sits, I see that there are 5000 lines in the production area and about another 10500 lines in my test area. For me, this is a lot of work. In three years at my last position I produced less than 1000 lines of code total.<p>
Where should I go from here? Personally, I'd love to be able to understand the [Schwartzian Transform], but I think I have a long way to go before that becomes clear.<p>
My thanks to you all for helping me on my journey to Perl enlightenment.<p>
Neil