i have a perl script-
#!/usr/bin/perl;
my $email = '[a-zA-Z0-9._]+@[a-zA-Z0-9._]+.[a-zA-Z0-9._]{2,4}';
open(FILE,'emails');
while (<FILE>) {
my $emails_not_found = 1;
if ( m/$email/ ) {
print($_);
my $emails_not_found = 0;
}
if ( $emails_not_found ) {
print "no emails\n";
}
}
close FILE;
the file emails is:
sdfasd@asd
asdf
so, as you can see, the script will not match regex to any of the lines. however, it outputs this-
no emails
no emails
i want it to output 'no emails' ONCE if it doesn't match the regex pattern at all. If it only matches the regex pattern just once, it will print that line and output 'no emails' for the other line :( I just want it to output either JUST the lines with the emails, or output 1 line that says 'no emails'. Thanks in advance.