Tolgar
asked on
Whu do I get this error in PerL? Can't use string as a HASH ref while "strict refs"
I have a Perl code and it runs some checks on files and generates an html page based on the results.
I wrote the code in a bad way that the html file creation in part of the actual code. Now, I'd like to refactor my code and seperate the html page creation from the actual part where I run the checks.
In order to do that I need to collect all the output that I get from the actual part (running checks) and then I plan to write a sub function to writes this data to a file (html file).
To do that, I tried to use hashes but I get the following error:
This is part of my code:
I get the error for line 30 in this code snippet?
Can you please let me know what I am doing wrong?
I wrote the code in a bad way that the html file creation in part of the actual code. Now, I'd like to refactor my code and seperate the html page creation from the actual part where I run the checks.
In order to do that I need to collect all the output that I get from the actual part (running checks) and then I plan to write a sub function to writes this data to a file (html file).
To do that, I tried to use hashes but I get the following error:
Can't use string (" WARNING: The file type does no") as a HASH ref while "strict refs" in use
This is part of my code:
my %report = ();
foreach my $fileTobeChecked (@allFilesTobeChecked) {
$fileNo++;
$report{ $fileTobeChecked }{ 'fileNo' } = $fileNo;
SOME CODE IN HERE TO RUN CHECKS
foreach my $check (@Checks) {
$checkno++;
$report{ $fileTobeChecked }{ $checkno } = $check;
SOME CODE IN HERE
if ( $numerrors == 0 ) {
$CheckResult = 'PASSED';
$report{ $fileTobeChecked }{ $checkno }{ 'checkResult'} = $CheckResult;
}
else {
$CheckResult = 'FAILED';
$report{ $fileTobeChecked }{ $checkno }{ 'checkResult'} = $CheckResult;
}
SOME CODE IN HERE
if{
SOME CODE IN HERE
}
else{
($CheckResult, @arrayofmatches) = eval "$checkFunc('$fileTobeChecked')";
$report{ $fileTobeChecked }{ $checkno }{ 'checkResult'} = $CheckResult;
$report{ $fileTobeChecked }{ $checkno }{ 'arrayofmatches'} = @arrayofmatches;
}
I get the error for line 30 in this code snippet?
Can you please let me know what I am doing wrong?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
@FishMonger: I found the cause of the problem but I cannot think of a way to fix it.
Can you please take a look at the link for the follow up question?
https://www.experts-exchange.com/questions/27837106/Hoe-to-create-multidimensional-hash-in-Perl.html
Thanks,
Can you please take a look at the link for the follow up question?
https://www.experts-exchange.com/questions/27837106/Hoe-to-create-multidimensional-hash-in-Perl.html
Thanks,
I agree with FishMonger. One of these isn't being assigned a value that you think - somewhere:
$fileTobeChecked
$checkno
$CheckResult
Try printing to see what you get:
$fileTobeChecked
$checkno
$CheckResult
Try printing to see what you get:
else{
($CheckResult, @arrayofmatches) = eval "$checkFunc('$fileTobeChecked')";
print "$fileTobeChecked: $checkno: $CheckResult\n";
#$report{ $fileTobeChecked }{ $checkno }{ 'checkResult'} = $CheckResult;
#$report{ $fileTobeChecked }{ $checkno }{ 'arrayofmatches'} = @arrayofmatches;
}
ASKER
This the information I got from the debugger:
Open in new window