>>>>> "RD" == Rob Dixon <[email protected]> writes:
RD> On 02/03/2011 17:55, Matt 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?
RD> Hey Matt
RD> If your file is small then this subroutine will do what you need.
RD> sub file_contains {
RD> my $file, $string = @_;
you forgot the () around the my vars.
that will assign the count of @_ to $file. not what you want.
perl -le '@foo = qw( a b ) ;my $x, $y = @foo ; print "$x $y"'
2
RD> open $file, '<', $file or die $!;
RD> my %names = map { chomp; ($_ => 1) } <DATA>;
don't you mean <$file> there?
RD> return $names{$string};
RD> }
uri
--
Uri Guttman ------ [email protected] -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/