in reply to text file database - Objects?

I have a program that does something similar. Basically, I have a list of movies in a text file. I read each line and then parse the information into an anonymous hash. Then I stick a reference to the hash in a list. With the list, I can access every bit of data about every movie.

Here's a simplified snippet of the read and store code.

my @movieList = (); my $index = 0; open(DATA, $dataFile); while (<DATA>) { chomp; if (/^\s+$/) { next; } # skip blank lines in datafile my @data = split("\t"); my $title = &getString( shift(@data) ); my $year = &getString( shift(@data) ); my $movieRec = { 'index' => $index, 'title' => $title, 'year' => $year, }; push(@movieList, $movieRec); $index++; } # while close(DATA);

I hope this gives you some ideas.

Replies are listed 'Best First'.
Re: Re: text file database - Objects?
by svsingh (Priest) on May 09, 2003 at 13:18 UTC
    Minor correction: That's not an anonymous hash. Sorry about that.
      Hello again,

      Sorry for my delayed reply, I've been very busy.. Thank you for your replies, they gave me ideas and I have solved my problem!
      Pseudo code

      for($i = 0; $i < scalar($#file +1); $i++) { foreach ($file[$i]) { # <-- this is what solves it! chomp; ($stuff, $more_stuff) = split(/\|/); # ... } }

      I didn't really need to create a new object for each data entry.. although it would have been a nice experiment, I found an easier way of doing what I wanted.
      Thanks very much for your support, I appreciate it.

      ~Shibby