Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Get a Perl script to return content from a module

Posted on 2016-09-01
7
Medium Priority
?
102 Views
Last Modified: 2016-09-08
Hello, I’m simply trying to get the desired return from the attached perl module to print based on the standard input ($input is the subroutine parameter). I get no error until line 11 on test.plx when it reads…

Undefined subroutine &main::one called at test.plx line 11, <STDIN> line 1.

Please help. Thanks.
testScript.txt
testModule.txt
0
Comment
Question by:Tech_20
  • 4
  • 3
7 Comments
 
LVL 28

Expert Comment

by:FishMonger
ID: 41780255
Your module has a syntax errors (2 typos and a missing closing paren) and won't compile.

C:\test>perl -c test.pm
syntax error at test.pm line 12, near ") {"
Global symbol "$answer" requires explicit package name at test.pm line 14.
syntax error at test.pm line 14, near ") {"
test.pm had compilation errors.

Open in new window

0
 
LVL 28

Assisted Solution

by:FishMonger
FishMonger earned 2000 total points
ID: 41780294
Besides fixing those issues, if the module isn't in one of the dirs in the @INC array, you'll need to add a use lib statement so that the script will know where to look for it.
0
 

Author Comment

by:Tech_20
ID: 41780611
OK. Thanks. I'll fix the errors and add the @INC array.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 28

Expert Comment

by:FishMonger
ID: 41786429
Did you get the errors corrected?  Do you still need help fixing this problem?
0
 

Author Comment

by:Tech_20
ID: 41787848
Hello FishMonger,

Thanks for the advice. I fixed the @INC issue with this command,  export PERL5LIB=<module folder>

I found one missing parenthesis to correct. However, I still get this error and I'm not sure what else to correct in the module (see attached).

______
syntax error at .../test.pm line 14, near ") {"
Global symbol "$answer" requires explicit package name at .../test.pm line 16.
syntax error at .../test.pm line 16, near ") {"
Compilation failed in require at ./test.plx line 5.
BEGIN failed--compilation aborted at ./test.plx line 5.
______

Thanks.
textModule.txt
0
 
LVL 28

Accepted Solution

by:
FishMonger earned 2000 total points
ID: 41787957
c:\test>perl -c test.pm
POSIX syntax [: :] belongs inside character classes in regex; marked by <-- HERE in m/[:upper:] <-- HERE +/ at test.pm l
ine 13.
The error message is telling you that the [:upper:] needs to be inside a character class.  The brackets used in [:upper:] are taken literally so you need to add an additional pair of brackets around it to make it a character class.

sub one {
    my ($answer) = @_;
    if ($answer =~ /\?$/) {
        return "A?";
    } elsif ($answer =~ /[[:upper:]]+/) {
        return "B.";
    } elsif ($answer =~ /^\s*$/) {
        return "C!";
    } else {
       return "D.";
    }
}

Open in new window


Also note that I took out the extra 'my' declaration.
0
 

Author Closing Comment

by:Tech_20
ID: 41789528
Solved. Thanks FishMonger!
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

971 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question