Solved

Get a Perl script to return content from a module

Posted on 2016-09-01
7
82 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 500 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
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 500 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
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…

821 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