Match and return data based on my search criteria

Hi,
I'm kind of new to Perl so I appologize in advance! I'm trying to build a little Movie Database where the movies are stored in a datafile (for now). I've managed to set up adding new movies to the data file, it was pretty simple. I want to be able to search the datafile based on specific fields found in the data file (Like movie title or director, for example)

My code so far:

#!/usr/bin/perl

use CGI ":standard";
use Fcntl qw (:DEFAULT :flock);

print header;
print start_html("Searching Movies");


$movie_file = "../Movies.txt";
open(DAT, $movie_file) || die("Could not open file!");
@raw_data=<DAT>;
close(DAT);

#this is the search criteria from my html form
my($searchString)=(param("searchCriteria"));


#the delimiters in the file are "::" and each new movie is denoted by a new line

foreach $movie (@raw_data)
{
      chop($movie);
      ($title, $director, $year, $length, $genre, $rating, $review) =  split (/::/, $movie);
      if ($searchString =~/$title/) {print "Match FOUND. $searchString was found in $title"}

#I'm going to want to display all of the fields for the movie here in a pretty table of some sort
}

print end_html;

*** end code

So the code above seems pretty simple, I'm just not sure why I'm getting the output that I'm getting. For some reason it is printing $title as a blank character at this point. But if I were just to print $title outside of the IF statement, it will print the correct titles from the datafile. I think I'm misunderstanding how the "foreach $movie" is processing the datafile
Any ideas?

Thanks
-John


john946Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ozoCommented:
when $title is blank your if stateent would be
 if ($searchString =~//) {print "Match FOUND. $searchString was found in $title"}
// matches everything, since all strings contain an empty string
maybe you wanted
if( $title =~ /$searchString/ ){ print "Match FOUND. $searchString was found in $title" }

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
john946Author Commented:
Yup that was it!
Thanks for your help!!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.