Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cant use an undefined value as a Symbol reference at compare1.pl lin

Status
Not open for further replies.

aSDDSasdas

Programmer
Jul 12, 2006
19
AT
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,"> added.txt" or die "cant open added.txt for reading $!";
open my $txt4,"> deleted.txt"or die "Cant open deleted.txt for reading $!";
open my $txt5,"> 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.pl","/home/update_0609041028.txt","/home/update_0609041042.txt");


Note :i have eliminated the subroutines.
and line 66 is :eek:pen my $txt1,"< $filename1" or die "cant open $filename1 for reading $!"
 
your system call looks wrong to me
Code:
system("/home/compare1.pl","/home/update_0609041028.txt","/home/update_0609041042.txt");

I would write as
Code:
system("/usr/bin/perl /home/compare1.pl /home/update_0609041028.txt /home/update_0609041042.txt");

Your file open statements should look like
Code:
 open FH, "<$filename.txt";

chances are you haven't assigned anything to $txt1 ...

HTH

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
it looks like the file handles are causing the problem:

$txt1 through $txt5

just use regular filehandles instead of variables and you should be OK:

Code:
open (TXT1,"<$filename1") or die "cant open '$filename1' for reading $!";
open (TXT2,"<$filename2") or die "Cant open '$filename2' for reading $!";
open (TXT3,">added.txt") or die "cant open added.txt for reading $!";
open (TXT4,">deleted.txt") or die "Cant open deleted.txt for reading $!";
open (TXT5,">common.txt") or die "cant open common.txt for reading $!";

and reference the corresponding file handlw to work with the file:

Code:
while(<TXT1>) {
  ....
}
while(<TXT2>) {
   ...
}
etc
etc

next time post the entire error message you are getting.
 
Hi
Thank u for ur reply :)
the problem was with the filehandle.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top