Everything2
Near Matches
Ignore Exact
Full Text
Everything2

my first perl program

created by mcc

(thing) by mcc (2.7 y) (print)   ?   (I like it!) 1 C! Sat Aug 05 2000 at 23:17:16

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:


(thing) by WWWWolf (1.4 y) (print)   ?   (I like it!) Tue Sep 12 2000 at 22:14:23

(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. =)


(thing) by amelinda (4.2 y) (print)   ?   (I like it!) Tue Sep 12 2000 at 23:05:34

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.


printable version
chaos

Write like a Hacker Small helpful scripts for noders Learning Perl removing the ads in ICQ
Chipirones en su tinta How to recognize a fruit -p E2 Visual Basic hardlinking utility
-w Getting to know you nodes Subliminal linking script ISO 8859
September 12, 2000 GNU Chess use strict E2 Break Tag Utility
Actually A Inverse Kinematics August 6, 2000
night hard link GNU Recode Hamming sequence
Y'know, if you log in, you can write something here, or contact authors directly on the site. Create a New User if you don't already have an account.
  Epicenter
Login
Password

password reminder
register

Everything2 Help

Cool Staff Picks
Nodes to live by:
homeopathy
Horse chestnut
piano outside in the snow. and she was spinning
If a stereo system is made properly it can outperform any 5.1 digital system
Congratulations, you have eliminated all forms of hospitable life
Of the Terrible Doubt of Appearances
People shouldn't swallow rocks
Of Gingerbread Houses, and Happy Endings
Fred Astaire
Zazen
Paul Simon
June 30, 2006
Lamed Vav Zaddikim
New Writeups
SwimmingMonkey
Conversations with Fo Fo- the Loneliest dog in Purgatory(fiction)
locke baron
lynx(thing)
Simulacron3
Reality, Dimensions and the Natural Ontology(essay)
SubSane
Making Love to a 9-Foot Woman(person)
Ouzo
Thoughts(idea)
antigravpussy
I fall silent, listening. The breadcrumbs are talking about us(person)
calgon
Buffalo Bill by the pool(poetry)
gate
Anarchy is Order(idea)
ushdfgakjasgh
Scribeling(thing)
XWiz
Trism(review)
artman2003
Briefcase Full of Souls - Part I(fiction)
Dreamvirus
Alan Ladd(person)
waverider37
Harold Holt(person)
The Debutante
Until death do us part(fiction)
Ysardo
a brother to a sister(personal)
This affordable entertainment brought to you by The Everything Development Company