LiveJournal Data Mining

Ovid on 2004-01-18T22:39:13

Well, it's not really data mining but I wrote a program that would list the interests my friends have, ordered by the popularity of the given interest. As far as I can tell, LJ does not have robust tools for gathering said data, so I was forced to resort to HTML parsing. Yuck. The program has bugs, but it was a fun little exercise. I ran it for a friend of mine and curiously, he discovered that the most common interest for his friends was "cats", but he's not particularly fond of them. I, on the other hand, have a rather large number of friends interested in piercing, corsets, and candles (not the top interests, though.) I'll not speculate as to what that means.


Cool DRY-inspired idiom

jplindstrom on 2004-01-19T01:23:18

Very cool and useful idiom to declare variables inside the GetOpt call. I'll start doing that and not type things twice.

Thanks.

Re:Cool DRY-inspired idiom

Ovid on 2004-01-19T03:49:28

Thanks. I saw that in someone else's code and I realized that my has a return value: the variable that it's declaring. This is not exactly clear from the docs, though. Maybe I should submit a doc patch. Hmm.

Re:Cool DRY-inspired idiom

Dom2 on 2004-01-19T08:39:59

I like using it as part of an if statement:
if (my $foo = bar()) {
    print "I got $foo\n";
}

-Dom

Re:Cool DRY-inspired idiom

gav on 2004-01-20T17:16:55

I like the idiom but I've always been disapointed you can't write:
if (my $foo = bar() and $foo =~ /bar/) {
   print "\$foo is bar\n";
}

Re:Cool DRY-inspired idiom

Ovid on 2004-01-20T17:36:19

You can't do that because the variable doesn't come into scope until after the current statement finishes executing. Fortunately, that's an easy fix.

perl -le 'sub bar{ "baz" };if ((my $x = bar())=~/baz/){ print "yes" }'

Re:Cool DRY-inspired idiom

gav on 2004-02-09T18:43:55

The problem is that that causes a warning if bar() returns undef.