Re: Searching in a line



I wrote this now: If it finds the work beth in the line, then is
splits the line. otherwise print an error.
Now there is beth in the file ( i added it) but the program always
skips to the else statement, end prints it twice.
How should I modify the search if (/^beth/) ?

#!/usr/bin/perl

my $log = 'file.txt';

open my $fh, '<', $log or die "cannot open '$log': $!\n";

while ($data=<$fh>) {

if (/beth/) { #matches only if beth is in line
my $val =(split(/,/,$data))[3];
print $val, "\n";
}
else {
print ("Nope, not working...:\n");
}

}

close $fh;



.