Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Sunday November 30, 2003
03:06 PM

Another reason I like Perl

[ #16085 ]

I have the Robert Greenberg "How To Listen To and Understand Great Music" lecture series on 48 CDs, which I am importing into iTunes this weekend. While the first few CDs had entries in GraceNote (and I have talked about the pain of this before), most do not, so I need to label each track myself.

I have heard a lot of people complain about the sigils in Perl---those goofy characters before the variable name. They are so confusing!

Are they really more confusing than what I have to do to name variables in AppleScript (or Java, C++, Python, ...)? Since these things do not have special ways to denote variables, instead of naming the variable "index", which seems a good and proper name for a loop index, I have to find something else because "index", in AppleScript, is a keyword. In the same fashion I was bit by Python's "count", a good and proper name for a count of things. I end up putting a lot of possessives or articles in front of the name I really want, so they come out like "myIndex" or "theCount" ("Two glorious names, ah, ah, aaah!").


tell application "iTunes"
    copy (a reference to (get view of front window)) to thisPlaylist
    set theLesson to the text returned of (display dialog "Enter the lesson:" default answer "")
    -- if no tracks are selected, use them all
    if selection is {} then
        copy every file track of thisPlaylist to allTracks
        copy selection to allTracks
    end if
    set listLength to length of allTracks
    set subList to {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k"}
    set myIndex to 1
    repeat while myIndex ≤ listLength
        set aTrack to item myIndex of allTracks
        set aTrack's artist to "Robert Greenberg"
        set aTrack's album to "How To Listen To And Understand Great Music"
        set aTrack's name to "Lesson " & theLesson & (item myIndex of subList as string)
        set myIndex to myIndex + 1
    end repeat
end tell

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • This is just crying to be rewritten using Mac::Glue. :-)

    use warnings;
    use strict;
    use Mac::Glue ':all';
    my $itunes = new Mac::Glue 'iTunes';
    my $lesson = $itunes->display_dialog(
        'Enter the lesson:', default_answer => ''
    my $playlist  = $itunes->prop(view => window => 1);
    my @selection = $itunes->prop('selection')->get;
    my @tracks = @selection
        ? @selection

  • I know this journal entry is ancient, but I was considering getting that same music lecture series and would appreciate a capsule review.
    • I just finished Robert Greenberg's Operas of Mozart [], which I think is much better partly because I've gotten over his speaking style. The information is compelling and interesting, but his speaking style and cadence grates on me. His comedy is poorly delivered, but he just keeps on trying.

      That's just my opinion though. Everyone I know who has listened to Greenberg's levtures have been delighted by them.

      I'll be in New York next week, so you can hear one of the lectures if you like. They're all on my laptop