Solved

Get a Perl script to return content from a module

Posted on 2016-09-01
7
79 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!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

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 …
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 get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
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…

785 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