From the course: Perl 5 Essential Training

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Extracting matches

Extracting matches - Perl Tutorial

From the course: Perl 5 Essential Training

Start my 1-month free trial

Extracting matches

- [Voiceover] In a scalar context, the regular expression operator returns a logical value of true or false. Here is a working copy of match.pl from chapter nine of the exercise files. And here we're just checking to see if a match is found, and we have a logical "if" statement, and when I run it, it says "True", or, if there is no match, then it'll say "False". Sometimes it can be useful to know what the matches are, rather than just did it match. And you can do this with parentheses like this. If I put the word "line" in parentheses, and instead of "True" here, I say "match is $1", and instead of "False", I can just say "No match". And now when I run this, it says "match is line", and there is the text, the actual text that it matched. So, this is especially useful with wildcards. For example, if I change this to "..is" and I run it, now it matches the first time it finds two characters followed by "is", which is the word "This", and it shows that in our results. You can extract…

Contents