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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Perl exists error on HASH

Status
Not open for further replies.

Milleniumlegend

IS-IT--Management
Dec 16, 2003
135
I am getting the following Warning when trying to run the perl script. Could some one let me know what might be wrong.

Code:
foreach $f (@files) {
		my $tstamp;                  # timestamp for the files in foreach loop
		next if ($f eq "."); 
        next if ($f eq "..");
	# Add files to Hash if they do not exist.
	# Add Filestamp to Hash.
	if (! exists $binfiles[$f]) {
	     $fl = "$path\/$f";
	     $tstamp = &gettimestamp($fl);
	     &addtobintimestamp($fl, $tstamp);
	}
Argument "CA-PAYMENT-REPLACE.gnt" isn't numeric in exists at Scandir.pl line 128
.
 
It would help if you added line numbers so that we had a clue which line perl thinks is causing the problem.
Regardless, I think you should try swapping this:
Code:
if (! exists $binfiles[$f]) {
for this:
Code:
if (! exists $binfiles{$f}) {
I would guess that $binfiles should be a hash since you're using "exists" on it. If that is the case I also guess that "$f" is not numeric and therefore perl will get upset when you try to access an array with a non numeric index.

Trojan

 
Yes thats correct. $binfiles is a Hash. I was trying to check if the file already exists in the hash %binfiles. Most of the files are not numeric. They have names such as T999-test.gnt etc.

I will try with the curly braces for the exists on the Hash and see if this helps.

thanks
 
This is one reason for using the strict pragma in your programs. By using the square brackets, you're attempting to access the @binfiles array, whereas you intended to use the %binfiles hash, which is a totally different variable. If you'd used strict, this would have seen this instantly.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top