Kevin Old wrote:

> Hello everyone,
>
> Thanks to everyone who helped with my last problem last week.  I've hit
> a snag in another problem this week.
>
> I need to parse the following data:
>
> "COUNTRY MUSIC HALL OF FAME UPC#: 0-84296-22922-2"||||||"COUNTRY FEMALE
> PARTY SONGS VOL. 2  UPC#:  0-84296-28682-9"||||||"COUNTRY MALE PARTY
> SONGS VOL. 2   UPC#:  0-84296-28652-2"||| ||||||||||||||||||||||||||||||
> |||||||||||||||
> |||||||||||||||
> TRACK|||"MADE FAMOUS BY"|||TRACK|||"MADE FAMOUS BY"|||TRACK|||"MADE
> FAMOUS BY"
> " 1. CRAZY"|||"PATSY CLINE"|||" 1. SOME DAYS YOU GOTTA DANCE"|||"DIXIE
> CHICKS"|||" 1. THE LONG GOODBYE"|||"BROOKS & DUNN"
> " 2. ANGELS AMONG US"|||ALABAMA|||" 2. BLESSED"|||"MARTINA McBRIDE"|||"
> 2. MY LIST"|||"TOBY KEITH"
> " 3. I WILL ALWAYS LOVE YOU"|||"DOLLY PARTON"|||" 3. BRING ON THE
> RAIN"|||"JO DEE MESSINA W/ TIM McGRAW"|||" 3. THE COWBOY IN ME"|||"TIM
> McGRAW"
> " 4. ON THE ROAD AGAIN"|||"WILLIE NELSON"|||" 4. CAN'T FIGHT THE
> MOONLIGHT"|||"LEANN RIMES"|||" 4. I BREATHE IN, I BREATHE OUT"|||"CHRIS
> CAGLE"
> " 5. STAND BY YOUR MAN"|||"TAMMY WYNETTE"|||" 5. I'LL FLY
> AWAY"|||"ALISON KRAUSS W/ GILLIAN WELCH"|||" 5. YOUNG"|||"KENNY CHESNEY"
> " 6. FOREVER AND EVER AMEN"|||"RANDY TRAVIS"|||" 6. I HOPE YOU
> DANCE"|||"LEE ANN WOMACK"|||" 6. GOOD MORNING BEAUTIFUL"|||"STEVE HOLY"
> " 7. SMALL TOWN GIRL"|||"STEVE WARINER"|||" 7. I KEEP LOOKING"|||"SARA
> EVANS"|||" 7. WRAPPED AROUND"|||"BRAD PAISLEY"
> " 8. GRANDPA"|||"THE JUDDS"|||" 8. WHEN YOU LIE NEXT TO ME"|||"KELLIE
> COFFEY"|||" 8. THAT'S WHEN I LOVE YOU"|||"PHIL VASSAR"
> " 9. BORN TO BOOGIE"|||"HANK WILLIAMS, JR."|||" 9. DOWNTIME"|||"JO DEE
> MESSINA"|||" 9. WHAT IF SHE'S AN ANGEL"|||"TOMMY SHANE STEINER"
> "10. YOU NEEDED ME"|||"ANNE MURRAY"|||"10. MAYBE, MAYBE NOT"|||"MINDY
> McCREADY"|||"10. MODERN DAY BONNIE & CLYDE"|||"TRAVIS TRITT"
> "11. THE GAMBLER"|||"KENNY ROGERS"|||"11. INSIDE OUT"|||"TRISHA
> YEARWOOD"|||"11. IN ANOTHER WORLD"|||"JOE DIFFIE"
> "12. I FALL TO PIECES"|||"PATSY CLINE"|||"12. THERE YOU'LL BE"|||"FAITH
> HILL"|||"12. I AM A MAN OF CONSTANT SORROW"|||"SOGGY BOTTOM BOYS"
> "13. SNAP YOUR FINGERS"|||"RONNIE MILSAP"|||"13. I DON'T WANT YOU TO
> GO"|||"CAROLYN DAWN JOHNSON"|||"13. WRAPPED UP IN YOU"|||"GARTH BROOKS"
> "14. TWO MORE BOTTLES OF WINE"|||"EMMYLOU HARRIS"|||"14. I NEED
> YOU"|||"LEANN RIMES"|||"14. NOT A DAY GOES BY"|||LONESTAR
> "15. OCEAN FRONT PROPERTY"|||"GEORGE STRAIT"|||"15. WHAT I REALLY MEANT
> TO SAY"|||"CYNDI THOMSON"|||"15. I SHOULD BE SLEEPING"|||"EMERSON DRIVE"
> "16. SOME KIND OF TROUBLE"|||"TANYA TUCKER"|||"16. THAT'S THE WAY"|||"JO
> DEE MESSINA"|||"16. I WANNA TALK ABOUT ME"|||"TOBY KEITH
>
> Now, let me explain the data.  There are 3 albums here.  The titles and
> UPC's are in the first line.  I have a loop that separates the title and
> the piece of the UPC that I need and puts it into a hash.
>
> my %titles = ();
> while(<KB>) {
>
>         my @songs;
>         my @artist;
>         my @line = split/\|/,$_;
>         foreach ($line[0], $line[6], $line[12]) {

Are your lines really all uniform?  It certainly doesn't look that way in
the file you attach farther down the thread.  I'd say the outer while loop
is alright, since it just keeps you moving through the file, but it seems
pretty clear That there is a mutlilevel organization here.

>
>
>                 if($_
>                 $_ =~ s/"//g;
>                 $_ =~ /^(.*?)\s+UPC#:\s+0-84296-(\d+)-\d/g;
>                 my $title = $1;
>                 my $upc = $2;
>                 $titles{$upc}{title} = $title;
>         }
>
> }
>
> Then the rest of the lines are "Tracks" and "Artists".  What I need to
> do is get the appropriate tracks and artists in respective (@tracks,
> @artists) arrays inside the hash.
>
> Basically, I need to know how to write code that does this:
>
> Get the 3 albums to be processed, put title in hash with UPC as key
> (done with code above)
>
> Parse next 16 lines (3 tracks and artists on each line) and associate
> them with the proper song & artist arrays in the hash.
>
> I know this is rather confusing, but any help is appreciated!
>
> Kevin
>
> --
> Kevin Old <[EMAIL PROTECTED]>

I'd probably do something like:
my $albums = {};
my $line - <KB>;
while ($line) {
   my $title;
   ($title, $line) = process_album_title($line);
   $line = get_album_cuts($line, $title, $albums);
}

You are working with a profoundly nasty data format here, but that probably
can't be helped.  It does seem to have a cyclic regularity, but not on a
line-by-line basis.  Therefore, your looping shouldn't be based on lines.
That sort of looping is for data in much more regular formats.

Joseph




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to