Perl script matching a certain patern
- by kivien
Assuming the file.txt is as follows:-
John Depp is a great guy.
He is very inteligent.
He can do anything.
Come and meet John Depp.
The perl code is as follows:-
open ( FILE, "file.txt" ) || die "can't open file!";
@lines = <FILE>;
close (FILE);
$string = "John Depp";
foreach $line (@lines) {
if ($line =~ $string) { print "$line"; }
}
…