CodeToad Forums » Perl » Cant use an undefined value as a Symbol reference at compare1.pl line 66
|
|
|
Hello ,
i have this program for which i do not know yet where exactly the problem is . i guess it is something to do in defining a variable or maybe with my arguments which are defined maybe in a proper manner . would be gratefull for any advice
compare1.pl
#!/usr/bin/perl
use strict;
use warnings;
# initialise
my %diff ;
my %diff1 ;
my %diff2 ;
my ($filename1, $filename2) = @ARGV;
@ARGV=2 or die "Usage : There should be 2 arguments";
open my $txt1,"< $filename1" or die "cant open '$filename1' for reading $!";
open my $txt2,"< $filename2" or die "Cant open '$filename2' for reading $!";
open my $txt3,"/forum/gt_added.txt" or die "cant open added.txt for reading $!";
open my $txt4,"/forum/gt_deleted.txt"or die "Cant open deleted.txt for reading $!";
open my $txt5,"/forum/gt_common.txt" or die "cant open common.txt for reading $!";
# create a hash table
while (<$txt2>)
{
$diff{strip($_)} = 1;
}
# extract added/deleted values
while(<$txt1>)
{
print $txt3 $_ unless (check_content($_) || !(eliminate(strip($_))));
}
close $txt1;
close $txt2;
close $txt3;
................................................................
test.pl
#!/usr/bin/perl
use strict;
use warnings;
system("/home/compare1.html","/home/update_0609041028.txt","/home/update_0609041042.txt");
Note :i have eliminated the subroutines.
|
|
|
Edit : I forgot to specify line 66
open my $txt1,"< $filename1" or die "cant open $filename1 for reading $!"
|
|
|
I dont see a line 66 in this code.
your getting that error becase the code is using strict;. Not a big deal, I personaly like to use strict and warn. Once all the bugs are worked out the code will run faster.
if your having some problems with undefined value in the code using "use var qw( );" can help. Adding the veriables in var is just like doing this "my %diff1;".
#!/usr/bin/perl
use strict;
# initialise global variables.
use vars qw(
$txt1 $txt2 $txt3 $txt4 $txt5
%diff %diff1 %diff2
);
use warnings;
my ($filename1, $filename2) = @ARGV;
@ARGV=2 or die "Usage : There should be 2 arguments";
open $txt1,"< $filename1" or die "cant open '$filename1' for reading $!";
open $txt2,"< $filename2" or die "Cant open '$filename2' for reading $!";
open $txt3,"/forum/gt_added.txt" or die "cant open added.txt for reading $!";
open $txt4,"/forum/gt_deleted.txt"or die "Cant open deleted.txt for reading $!";
open $txt5,"/forum/gt_common.txt" or die "cant open common.txt for reading $!";
est.........
Hope that helps,
Flex
|
|
|
|
|
|
|
// |