I have a text file called alert2.
if $ip matches any line in alert2 then I want that line to be erased from the file.
this is what I have, but it doesn't work because it isn't a hash. Can someone tell me how to do that??
Thanks,
Jewel
#Delete it from alert2
sub DeleteIt{
$| = 1;
# open file and define a handle for it
open(FILE,">>/root/alert2" || die "Unable to open alert2!\n";
# suck the file into an array
@file = <FILE>;
# use a loop to keep reading the file
# until it reaches the end
foreach $line (@file)
{
if ($line =~ $ip){
delete $line;
}
}
# close file when done
close(FILE);
return;
} When faced with a decision, always ask, 'Which would be the most fun?'
if $ip matches any line in alert2 then I want that line to be erased from the file.
this is what I have, but it doesn't work because it isn't a hash. Can someone tell me how to do that??
Thanks,
Jewel
#Delete it from alert2
sub DeleteIt{
$| = 1;
# open file and define a handle for it
open(FILE,">>/root/alert2" || die "Unable to open alert2!\n";
# suck the file into an array
@file = <FILE>;
# use a loop to keep reading the file
# until it reaches the end
foreach $line (@file)
{
if ($line =~ $ip){
delete $line;
}
}
# close file when done
close(FILE);
return;
} When faced with a decision, always ask, 'Which would be the most fun?'