I actually wrote my first perl program last night. I read Learning Perl a couple weeks ago, but i didn't get around to actually writing anything until last night..

All the program does is take a text file and wrap square brackets around every single word in the file. In other words, it's an automatic hard link generator. It's smart enough to ignore all HTML tags and entities and anything that is already hardlinked. It also recognizes apostrophes as being part of the word. And it works. And its source code is completely unreadable.

Here it is, followed by its output when given a text file containing this writeup as an argument:


#!/usr/bin/perl
open(FHA, $ARGV[0]) or die "Input file unspecified or broken";
undef $/; $_ = <FHA>;
s/((?:(?:\<[^\>]*\>|\[[^\]]*\]|\&\w*\;)[^\w\<\[\&]*)*)([\'\w]+)/$1\[$2\]/g;
print $_;
I actually wrote my first perl program last night. I read Learning Perl a couple weeks ago, but i didn't get around to actually writing anything until last night..

All the program does is take a text file and wrap square brackets around every single word in the file. In other words, it's an automatic hard link generator. It's smart enough to ignore all HTML tags and entities and anything that is already hardlinked. It also recognizes apostrophes as being part of the word. And it works. And its source code is completely unreadable.

Here it is, followed by its output when given a text file containing this writeup as an argument:

(Note for downvoters: No, this is not your average "getting to know you" node - this is more of an example of how the Horrors of the Past can Come to Haunt You. =)

Tale of Truly Dusty Code

This is the first Perl script I remember having written:

#!/usr/bin/perl
# CoolFilter (c) Urpo Lankinen 26th Oct 1996
while($_=<>){y/a-zåäö/A-ZÅÄÖ/;y/A-Z/ABKD3F6H1JK-N0P-ZT-XUZ/;print($_);}

Yeah, it's a k00l wAR3z k1dd13 3mUl8tR. Handle with excessive sarcasm!

What it does? Well, it does this character mapping (Characters on upper line translate to corresponding character on lower. Lowercase characters are translated to uppercase characters.)

ABCDEFGHIJKLMNOPQRSTUVWXYZÅÄÖ
ABKD3F6H1JKLMN0PQRZTUVWXUZÅÄÖ

Problems with this one?

Ugh. No -w, no use strict; (Well, not using it in all of my scripts when I bloody well ought to), and seddish "y" instead of "tr". Grr. And while I aimed for self-containiness, I used the while loop when I could have used -p. And speaking of print, it uses redundant argument. Also, for locale independentness, uc operator would do better job at uppercasifying...

But it works. That's important. =)

This isn't (or maybe is) the first Perl program I've written; I wrote the first feeble scripts under DOS and Perl 4. The laptop's hard disk just died painfully once, before I had backed up everything... but don't worry, I lost interest completely when none of the stuff I tried to do worked and I couldn't understand any of the bundled library files. I'm more grieving the loss of the Turbo Pascal code...

I guess I picked up that construct from Perl 4 manual pages and then forgot it. Anyway, I started seriously learning Perl when I got Linux (in late summer 1996, I guess) and it had Perl 5. I didn't knew Perl well until summer 1997, when I got a copy of the Camel Book and realized how much fun Perl can be.

The rest, as they say, is history. =)

Funny sidenote: That same day, I wrote skibm2latin1.pl and sklatin12ibm.pl, two scripts to translate Latin-1 scandinavic characters to IBM codepage 437 and vice versa. I have used those scripts until this month [Sep 2000] when I finally installed Recode to handle this stuff. Speak of dusty code that gets used forever and ever without being noticed... Perl is Built to Stay. =)

My very first perl program: (from a couple years ago)

#!/usr/bin/perl
# first tries at random sigs

@str=split(/\s+/o,`ls sigs/`);
srand;
`rm /nfs/user/l/lillith/.signature`;
`cp /nfs/user/l/lillith/sigs/@str[rand(@str)] /nfs/user/l/lillith/.signature`;
After contemplating this as many, many lines of C++ code, I was happily amazed that I could cut it down to 7 lines.

Of course, then I showed it to a friend who scrunched it down to 4, including the #!/usr/bin/perl.

Log in or register to write something here or to contact authors.