# Converts a playlist (exported from iTunes) to a Perl
#  data structure (a list of hashes).
# Copyright 2004 Mark T. Abbott

# Includes and global variables.

use strict;

# Primary routines.

sub parse_playlist
# Read an iTunes Playlist export file on STDIN and generate
#  a corresponding data structure.
{
	# Change the file separator to \r to match the playlist file format.
	$/ = "\r";

	# Get the field list from the first line of the playlist file.
	chomp (my $fields = <>);
	my @fields = split /\t/, $fields;
	warn join ':', @fields;

	# Each remaining line contains info on one track.
	my @tracks;
	while (<>)
	{
		chomp;
		my @vals = split /\t/;
		my %h = ();
		map { $h{$fields[$_]} = $vals[$_] } 0..$#fields;
		push @tracks, \%h;
	}

	return @tracks;
}

1;

