The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Erwin Data Structures 2.1.79937 (Default branch) iBot Software Releases - RSS News 0 04-22-2008 04:30 PM
Sux data structures 1.0.1 (Default branch) iBot Software Releases - RSS News 0 04-14-2008 02:40 AM
Sux data structures 1.0 (Default branch) iBot Software Releases - RSS News 0 04-07-2008 01:20 AM
Building a Hybrid Data Warehouse Model iBot Oracle Updates (RSS) 0 04-06-2008 06:10 AM
Sux data structures 0.3 (Default branch) iBot Software Releases - RSS News 0 02-21-2008 03:20 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-21-2002
Optimus_P Optimus_P is offline Forum Advisor  
flim flam flamma jamma
  
 

Join Date: May 2001
Location: Chicago IL, USA
Posts: 1,006
building perl data structures on the fly

Objective: at the moment build a logical data structure to hold the GENRE, ARTIST-ALBUM,SONG TITILES.

PURPOSE: to catalog my own MP3 collection. for view on the web.

END RESULT: it will go on a CGI webpage and people can search by GENRE or artist name/album.

I was thinking about useing a 3 dementional array. but then i was also thinking about an array with hash referances to an array.

i am unsure.

anyways, any help with building a logical data structure on the fly would be much appricated.


Code:
SCRIPT:

#!/usr/bin/perl -w

$FFILE = "testlist.txt";

open SONG, $FFILE or die "NO GO ($!)";
foreach (<SONG>) {
        chomp;
        push(@holdit, $_) if $_ =~ /Directory of/ || $_ =~ /\.mp3/;
};

$count=0;
DIR: foreach (@holdit) {
$count++;

        if (($_ =~ /\w*\s\w*\s\w:\\\w*\\\w*\\(\w*\s?\w*)\\(.*)/) && ($holdit[$count] !~ /Directory of/)){
                print "\nGENRE:$1     TITLE: $2\n";
        }
        elsif ($_ =~ /mp3/) {
                $SONG=substr($_,39);
                print "SONG:$SONG\n";
        }

}


Code:
SAMPLE OUTPUT:
GENRE:Rock     TITLE: Pink Floyd - Delicate Sound of Thunder\Disc 1
SONG:01 - Shine on You Crazy Diamond.mp3
SONG:02 - Learning to Fly.mp3
SONG:03 - Yet Another Movie.mp3
SONG:04 - Round and Around.mp3
SONG:05 - Sorrow.mp3
SONG:06 - The Dogs of War.mp3
SONG:07 - On the Turning Away.mp3

GENRE:Rock     TITLE: Pink Floyd - Delicate Sound of Thunder\Disc 2
SONG:01 - One Of These Days.mp3
SONG:02 - Time.mp3
SONG:03 - Wish You Were Here.mp3
SONG:04 - Us And Them.mp3
SONG:05 - Money.mp3
SONG:06 - Another Brick In The Wall, Part Ii.mp3
SONG:07 - Comfortably Numb.mp3
SONG:08 - Run Like Hell.mp3

GENRE:MY GROUP     TITLE: MY ARTIST - MY ALBUM
SONG:02 - MY SONG.mp3

  #2 (permalink)  
Old 10-21-2002
Optimus_P Optimus_P is offline Forum Advisor  
flim flam flamma jamma
  
 

Join Date: May 2001
Location: Chicago IL, USA
Posts: 1,006
mmm or should perl with XML be the choosen weapon for this battle?

any thoughts? suggestions? examples?
  #3 (permalink)  
Old 10-21-2002
Neo's Avatar
Neo Neo is online now Forum Staff  
Administrator
  
 

Join Date: Sep 2000
Location: Asia Pacific
Posts: 6,797
PHP and MySQL would be my choice.....
  #4 (permalink)  
Old 10-22-2002
auswipe's Avatar
auswipe auswipe is offline Forum Advisor  
Registered User
  
 

Join Date: Nov 2001
Location: Wide Awake Wylie, Texas
Posts: 535
I would use a hash with anonymous references to another hash.

Ala:


Code:
$recordHash{"Rock"}{"Pink Floyd - Delicate Sound of Thunder\Disc 1"} = \@arrayOfSongs;

I really like anonymous hashes. It has made by life much easier in the past. Plus it is real handy for listing out the entire contents of the hash, ala:


Code:
foreach $genre (sort(keys(%recordHash))) {
  foreach $album (sort(keys(%{$recordHash{$genre}})))
    print "$genre - $album";
    # handle the array that $recordHash{$genre}{$album} is pointing to here.
  };
};

I think that the neatest thing about anonymous hashes is that all the Genre's would be grouped together under the hash (1->M relationship) and you wouldn't have to worry about duplicatation of genre in an array.
  #5 (permalink)  
Old 10-22-2002
Optimus_P Optimus_P is offline Forum Advisor  
flim flam flamma jamma
  
 

Join Date: May 2001
Location: Chicago IL, USA
Posts: 1,006
Quote:
Originally posted by Neo
PHP and MySQL would be my choice.....
you know my coworkers said the same thing.... well to use a db anyways. but its not fesiable as i dont have it installed and its not portable, the list will live on a remote machine and updated when ever i get around to it.


auswipe: thanks for the snipit. i will deffinetly be looking into it.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 01:46 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0