Solved

Get a Perl script to return content from a module

Posted on 2016-09-01
7
86 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
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…

752 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