Perl

Filehandles with forks

December 8th, 2003

I was debugging a Perl script last week and wanted to know why a command in an open statement ended with a pipe. For example:

open MYFILEHANDLE,"decode myDB|" or die "Failed to decode the database.";

The answer is that the pipe forks a new process. This is explained here:
http://www.perldoc.com/perl5.8.0/pod/func/open.html

While looking I came across good little Perl tutorial:
http://www.geocities.com/SiliconValley/Vista/6493/perl/tutorial.html

Leave a comment

 

Generating an HTML representation of a Perl script

November 21st, 2003

I'm trying to sort out the main part of my site. It needs a proper home page for starters. So I was looking at sites and grabbing bits of HTML that I thought might be useful. In doing so it became clear that life would be easier if I could take my cut and pasted bits of HTML and run them through a "pretty printer" to reformat the code in a consistent and easier to read design. There's got to be loads of programs out there that'll do that, I thought - I'll just go and get one.

It turned out to be harder to find what I wanted than I thought it would be. But while looking I came across something I'd heard of, or read about, at some time, but never gone and tried before. It's a Perl reformatter called perltidy. You can get it at SourceForge.

You can download a ZIP file. But you then need to "make" the install. I use Windows XP and ActiveState Perl. I tried the "make" command, but I obviously didn't have make. However, this isn't a problem. You can download nmake from Microsoft at http://download.microsoft.com/download/vc15/Patch/1.52/W95/EN-US/Nmake15.exe. This is a self-extracting executable that puts the files nmake.exe and nmake.err in the same directory. All you need to do is move them to a directory that's in your PATH and you can use nmake instead of make.

The result is a program called perltidy that tidies up your Perl scripts. However, that's not of so much interest to me because I'm quite obsessive about spacing, indenting, aligning and commenting my Perl code. What's really good about perltidy is that you can run it on your Perl script with the -html flag (e.g. perltidy -html myscript.pl) and it outputs an HTML file that you can use to display your script on a website.

It works really sweetly and the results are great. If I had time I'd stick a page up here so that you could see what I mean, but that'll have to wait. I've got lots of other stuff to do. Like the website. I still haven't found that HTML reformatter. But perltidy is a nice find and I can thoroughly recommend it, as long as you're okay about using command-line tools.

Leave a comment



^ back to top ^

Page 3 of 3123