Solved

Get a Perl script to return content from a module

Posted on 2016-09-01
7
62 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Utilizing an array to gracefully append to a list of EmailAddresses
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…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

758 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now