I am new to perl programming. I have a scenario where a username is entered in a file, lets say info.log
. So, now I want to check whether this username is present in the file contents or not
$user = $ENV{USER};
open (READ_USER_INFO_LOG, "info.log") || die("-E- Unable to open \"info.log\n");
@content = <READ_USER_INFO_LOG>;
close READ_USER_INFO_LOG;
foreach $line(@content)
{
if($line has $user)
{
print "Usenrmae found";
break;
}
}