Avatar of Tolgar
Tolgar
 asked on

Why can't I use string as a subroutine ref while "strict refs" in use in Perl?

Hi,
I get the following error after using dereferencing:

Can't use string ("errorIDsInCatchblocks") as a subroutine ref while "strict refs" in use at

Open in new window

                                           
This is the code I have:

my $nonStrictCheckResult = $check->($fileTobeSubmitted);

Open in new window

                                           
Why do I get this error and how can I fix it without compromising use strict?

Thanks,
Perl

Avatar of undefined
Last Comment
wilcoxon

8/22/2022 - Mon
Tolgar

ASKER
Ok. I now use eval and this fixed the previous problem. But I still have problem.

Let me show you the big picture:

I have a Perl module  (FullyqualifiedNames.pm):

#!/usr/local/apps/bat/latest/bin/perl -w
package stdModules::FullyqualifiedNames;
use strict;
use warnings;

use Exporter 'import';
our @EXPORT = qw(FullyqualifiedNames);

sub FullyqualifiedNames{
my ($file) = @_;
my @line_numbers;

open (FILE, $file) or die "Couldn't open $file: $!\n";
my @data = <FILE>;
close(FILE);

my $lineno = 0;
my $result;

foreach my $line (@data) {
		$lineno++;
		if ($line =~ /^import(.*)\*/) {
			push (@line_numbers,$lineno);
		}
	}
	if (scalar(@line_numbers)) {
		#return (0,@line_numbers);
		$result = 'Fail';
		return $result;
	}
	else {
		#return (1,@line_numbers);
		$result = 'Pass';
		return $result;
	}
}
1;

Open in new window


I would like to call this module from another Perl module. In order to do that I have done the followings to the other Perl module which is called runCheck.pm

I have the following line in the beginning which makes it a package:
package stdModules::runCheck;

Open in new window


I added the following line (standardsRepository is the name of the directory where FullyqualifiedNames lives.)
use standardsRepository::FullyqualifiedNames;

Open in new window


Then I have some more code and finally I run the following command:
my $Result = eval "$check('$fileTobeSubmitted')";

Open in new window



However, this does not return anything. Therefore, $result is undef.

Can you please let me know what I am doing wring and how I can fix it?

Thanks,
ASKER CERTIFIED SOLUTION
wilcoxon

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck