Link to home
Start Free TrialLog in
Avatar of Tolgar

asked on

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

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?

Avatar of Tolgar


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  (

#!/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>;

my $lineno = 0;
my $result;

foreach my $line (@data) {
		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;

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

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?

Avatar of wilcoxon
Flag of United States of America image

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