in reply to regex issue

Your file contains the name and the age on each line.

However, since you anchor the search with the ^ at the start and the $ at the end, and you're only looking for the name, it can't match.

You could match with /^\Q$student\E\s+\d+$/ - Student name, one or more blanks, one or more digits.

Replies are listed 'Best First'.
Re: Re: regex issue
by Anonymous Monk on Feb 27, 2004 at 21:35 UTC
    using the index work but it only checks for the name , I am trying to see if the age match as well, I will skip that line only if the name and age match. thanks
      Well, then, you need to match on both the name and the age:
      $found = 1 if /^\s*\Q$student\E\s+\Q$studentAge\E\s*$/
      should do the trick. If no one else ever touches the file, you can get away with eliminating with \s* on either side, but I figure they don't hurt, on the off chance someone brings the data file into an editor at some point.