http://www.perlmonks.org?node_id=125304

amulcahy has asked for the wisdom of the Perl Monks concerning the following question:

Hello All,

I want to search through a text file for a supplied pattern and if it exists -> do nothing. If not -> add the the text to the file.
The code I am using is:
$tempName= $query->param('searchText'); #user supplied open (FILE, "+>>filename"); @file = <FILE>; $temp = join('',@file); $temp =~ /$tempName/s; if ($temp eq '') { print FILE $tempName . "\n"; } close (FILE);
The format of the text in the file to be searched is like:

/home/Ireland/amu/amutest/automated.abc

My problem is that the searchText is always added to the file as the search never seems to find anything.

Follow-up query:
For testing purposes I am only searching for "auto" but in the completed program I will be searching for the entire path. Will the inclusion of "/" in the search cause more problems, e.g. In the above code $tempName could be

$tempName = /home/Ireland/amu/amutest/manual.abc
Thanks

AM