Click to See Complete Forum and Search --> : Loading from file


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

scandog
11-01-2005, 02:53 PM
Sorry when I said it prints nothing I ment to say it will print everything including the line that it is not supposed to print.

Jeff Mott
11-02-2005, 09:44 PM
Since Perl is loosly typed it provides two sets of operaters for comparing strings and for comparing numbers. So '0' == '00' is true (numeric comparison) but '0' eq '00' is false (string comparison). It seems like you need to use string comparisons where you are currently using numeric comparisons.