scandog
11-01-2005, 02:50 PM
Hi,
I am loading a line from a file and then trying to compare that line to a another file that I load in.
When I step through the second file and have it look for the line in the first it never works.
I am new to perl but if its similar to c++ / php I would think what I am doing should work fine.
Here is my code
#!/usr/bin/perl
$userlist ="/var/www/html/updatelist.txt";
open(DAT, $userlist) or die ("Cannt Open File");
@raw_data=<DAT>;
close(DAT);
$filtergroups="/etc/dansguardian/filtergroupslist";
open(DAT, $filtergroups) or die ("Can't open file");
@data=<DAT>;
close(DAT);
open(DAT,">$filtergroups") or die("Can't open file");
foreach $dansfilter (@data)
{
#print DAT "$dansfilter";
#print $raw_data[0];
#print $dansfilter;
if(chomp($dansfilter) != chomp($raw_data[0]))
{
#print "they are the same";
print DAT "$dansfilter";
print DAT "\n";
}
}
close(DAT);
updatelist.txt file
test=test1
filtergroupslist
....
test2=test2
test3=test3
test=test1
What am I doing wrong?
I can change the file to print the same if the if statement is changed to == and it will print it one so I know it is finding it but if I run it other wise it prints nothing.
thanks
I am loading a line from a file and then trying to compare that line to a another file that I load in.
When I step through the second file and have it look for the line in the first it never works.
I am new to perl but if its similar to c++ / php I would think what I am doing should work fine.
Here is my code
#!/usr/bin/perl
$userlist ="/var/www/html/updatelist.txt";
open(DAT, $userlist) or die ("Cannt Open File");
@raw_data=<DAT>;
close(DAT);
$filtergroups="/etc/dansguardian/filtergroupslist";
open(DAT, $filtergroups) or die ("Can't open file");
@data=<DAT>;
close(DAT);
open(DAT,">$filtergroups") or die("Can't open file");
foreach $dansfilter (@data)
{
#print DAT "$dansfilter";
#print $raw_data[0];
#print $dansfilter;
if(chomp($dansfilter) != chomp($raw_data[0]))
{
#print "they are the same";
print DAT "$dansfilter";
print DAT "\n";
}
}
close(DAT);
updatelist.txt file
test=test1
filtergroupslist
....
test2=test2
test3=test3
test=test1
What am I doing wrong?
I can change the file to print the same if the if statement is changed to == and it will print it one so I know it is finding it but if I run it other wise it prints nothing.
thanks