learingperl01
MIS
Hello all I have a script that I am working on. I am trying to print the entire contents of a file when a regex match is found once instead of what $_ is holding after a match.
So if a match is found I want to stop looking and just print the entire contents of the file. I am kinda stuck as to how to escape the while loop in order to print the entire contents instead of just the line that matches the regex.
Instead of adding/working with the entire script I just created another script with the part that I am having trouble with. Below is a sample script that I am trying to get this part working.
Thanks for the help in advanced.
So if a match is found I want to stop looking and just print the entire contents of the file. I am kinda stuck as to how to escape the while loop in order to print the entire contents instead of just the line that matches the regex.
Instead of adding/working with the entire script I just created another script with the part that I am having trouble with. Below is a sample script that I am trying to get this part working.
Thanks for the help in advanced.
Code:
#!/usr/bin/perl
use strict;
use warnings;
my $search_file = $ARGV[0];
open( DATA_FILE, "< $search_file" ) or die "Can't open $search_file : $!";
while ( <DATA_FILE> ) {
if ( $_ =~ /Test/smgi ) {
print "$_";
}
}