Link to home
Start Free TrialLog in
Avatar of cucugirl
cucugirl

asked on

error in code

ok.. so this is what i got for my code right now guys... when i add the last if statement
                        if(!Check($value, @POptions)){
                              delete $ghash{$value} or die "$!";
                        }

it says that the hash %ghash is empty when i try to print it.. do you guys have any idea why this is happening?

use constant DefaultInput   => "DEFAULT.txt";
use constant UserInput   => "USERINPUT.txt";
use constant gInput => "INPUT.txt";
 
 
my @Default = Default();
my @POptions = pinputs();
my @Attributes = attributes();
my %ghash;
 
 
if(-e gInput){
	my @input = &readinput(gInput);
	
		%ghash = @input;
			while (my ($entry, $value) = each %ghash){
				if(!Check($entry, @Attributes)){
					delete $ghash{$entry};
				}
			
				if(!Check($value, @POptions)){
					delete $ghash{$value} or die "$!";
				}
						
		
		
		}
	}
 
 
 
print Dumper \%ghash;
 
sub readinput{
	my $UserInput = shift;
	my @link;
	open(my $fh, "<", $UserInput) or die "Coudln't open file $!";
	close($UserInput);
		while(my $line = <$fh>){
				next if $line =~ /^\s*(?:#|$)/;
				push(@link,split(/:/,$line));
					}close($fh);					
	
	return @link;
					
}
 
sub pinputs{
my @inputs = ("67","97","2","3");
return @inputs;
}
 
sub attributes{
my @attributes = ("BOOK", "YEAR", "EDITORIAL");
return @attributes;
}
 
sub Check{
	my ($value, @array) = @_;
		foreach my $element (@array)	
			{	
				if($element =~ /\Q$value\E/){
					return 1;
	      				}
				
			}
		return 0;
	}

Open in new window

Avatar of cucugirl
cucugirl

ASKER

also when i put

                        if(!Check($value, @POptions)){
                              delete $ghash{$value} or die "$!";
                        }

it says the following error:
Bad file number at COPY.pl line 42.
Remove this on line 38:
    close($UserInput);
adam if i do that it says this:

Died at COPY.pl line 42.
delete $ghash{$value} or die "$!"; that is line 42
Can you attach the three text files this program uses (INPUT.txt, USERINPUT.txt, and DEFAULT.txt)?
these fails are just a snapshot... userinput will be longer
DEFAULT.txt
INPUT.txt
USERINPUT.txt
code is breaking up userinput where there is colon... default is just a masterlist of the files and input.txt is just a global input file
ASKER CERTIFIED SOLUTION
Avatar of Adam314
Adam314

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial