Match and return data based on my search criteria

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:


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!");

#this is the search criteria from my html form

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

foreach $movie (@raw_data)
      ($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?


Who is Participating?
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" }
john946Author Commented:
Yup that was it!
Thanks for your help!!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.