>-----Original Message-----
>From: Matt [mailto:lm7...@gmail.com]
>Sent: Wednesday, March 02, 2011 11:25
>To: beginners@perl.org
>Subject: Re: Testing File Contents
>
>> # Untested
>> use strict;
>> use warnings;
>> open my $fh, '<', my_file;
>> while(<$fh>){
>>     if ($_ !~ /my_string/) {
>>         # Do something
>>     }
>> }
>
>This triggers on EVERY line of the file that does not contain the
>string.  I just want to trigger once if its no where in the file.

        Add a simple switch which is set to zero. Then look for the value you 
want. When found then you should be able to set to nonzero and leave the while.
        Then you should be able to check:  if switch is not true, then send the 
email...

         If you have any questions and/or problems, please let me know. 
         Thanks. 
 
Wags ;) 
David R. Wagner 
Senior Programmer Analyst 
FedEx Services 
1.719.484.2097 Tel 
1.719.484.2419 Fax 
1.408.623.5963 Cell
http://Fedex.com/us



>
>
>> The other way would be on shell -
>> # Untested
>> grep my_string my_file
>> if [ $? -eq 1 ]
>> then
>>     echo "Do something"
>> fi
>> ~Parag
>>
>>
>>
>> On Wed, Mar 2, 2011 at 9:55 AM, Matt <lm7...@gmail.com> wrote:
>>>
>>> I am looking for a simple way to test if a file does not contain a
>>> string.  This is on a linux box.
>>>
>>> if myfile does not contain mystring {
>>>  #do_something;
>>>  }
>>>
>>> The file is basically a list of names and I want to test that a
>>> certain name is not in there.  Is there an easy way to do that?
>
>--
>To unsubscribe, e-mail: beginners-unsubscr...@perl.org
>For additional commands, e-mail: beginners-h...@perl.org
>http://learn.perl.org/
>


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to