Why I love to hate, to love, to hate, to love Perl

| 2 Comments | No TrackBacks
Show me another language where you can download the contents of a web page, scan it for a complex text pattern, stuff all of the entries into an array, and dump them to the console in so few lines of code:

#!/usr/bin/perl -w
use strict;

open(SLASHDOT, '<slashdot.html');
my $data;
while (<SLASHDOT>)
{
    $data .= $_;
}
close(SLASHDOT);
$_ = $data;
my (@stuff) = /attached to \<a href=\"[\/\:\?\.\;\w\%\=]+\"\>[^\>^\<]+\<\/a\>/g;
print "You have commented on ~$#stuff entires\n\n\n";
foreach my $s (@stuff)
{
    print "$s\n";
}
I through this script together while trying to figure out what regular expression syntax would work to extract all of the entries that I have commented on at my Slashdot user profile. It's not even as compact as it could be either, but then uber-compact Perl code has a tendency to offend my Java/C#-developer sensibilities. Though, there is something to be said about a programming language that can be so succinct that you can express the process of breaking a DVD's encryption in about seven lines of code. When you can read that, you can probably natively understand Ph'nglui mglw'nafh Cthulhu R'lyeh wgah'nagl fhtagn...

Related Entries:

No TrackBacks

TrackBack URL: http://www.codemonkeyramblings.com/mt/mt-trackback.cgi/484

2 Comments

Ia! Ia! C'thulu fhtagn!

Love the tagline at the top of the page, by the way.

Leave a comment

December 2008

Sun Mon Tue Wed Thu Fri Sat
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31      
OpenID accepted here Learn more about OpenID

Creative Commons License
This blog is licensed under a Creative Commons License.
Powered by Movable Type 4.21-en
   

Site Credits

   
        Wordpress Themes by TemplateLite