in reply to perl and apache2 on ubuntu 17.04

thank you so much for ALL of that input. it worked well, although it did take a while. managed to connect my www webaddress to my public IP and all is working as you might expect, mostly. at least, Apache is now returning SOMETHING...albeit very confusing.

you see, an issue has cropped up since these changes. now none of my modules work. my main site code (for .pl scripts) is stored in the /var/www/html/ and my modules are stored in /var/www/html/Pm

here's a simple module i have stored in /var/www/html/Pm/ - it's just my 'TEMPLATE.pm' so i don't mess up making new modules:
package Pm::TEMPLATE; # change TEMPLATE to whatever you need it to be #/ # a template pm so i don't gotta type all this all the time #/ use strict; use warnings; use Exporter; use vars qw($VERSION @ISA @EXPORT_OK); use CGI; $VERSION = 1.00; @ISA = qw(Exporter); @EXPORT_OK = qw( an_exported_sub ); use lib "/var/www/html/Pm"; # in case other modules i make need to be +added into this module my $TABLE_BORDER = 0; my $DEBUG = 0; sub an_exported_sub($$) { #* # an exported sub description/information #* my ($param1, $param2) = @_; # param one && param 2 return 1; # a return value of 1 #usage: my $val = an_exported_sub($someval, $someotherval); } 1;
now...the main code mytest.pl (stored in /var/www/html/):
#!/usr/bin/perl # must have's! use strict; use warnings; use CGI::Carp qw(fatalsToBrowser); use DBI; use URI::Escape; use lib "/var/www/html/Pm"; use TEMPLATE qw(an_exported_sub); my $DEBUG = 0; my $output = "content-type: text/plain\n\n"; print $output . an_exported_sub(1, 2); exit 1;
i use geany and i can press F8 on TEMPLATE.pm - compiles just fine. press F8 on mytest.pl and it compiles just fine, too. so i'm a bit lost as to why an_exported_sub(1, 2) isn't found...which is unbelievably mind-boggling!

when i run this, i get the following error msg: Undefined subroutine &main::an_exported_sub called at /var/www/html/mytest.pl line 18.

Replies are listed 'Best First'.
Re^2: perl and apache2 on ubuntu 17.04
by huck (Prior) on Jul 18, 2017 at 23:07 UTC

    Under these conditions

    use lib "/var/www/html/Pm"; use TEMPLATE qw(an_exported_sub);
    shouldnt this
    package Pm::TEMPLATE;
    instead be this
    package TEMPLATE;

    added:Or instead do you want

    use lib "/var/www/html";

      omg! if that's the issue, wow...i've been struggling for hours. checking...

      yup. that worked (removing Pm:: from package statement)!! thank you so very much, huck! I will add those who have helped me in this to my "special thanks" section on my website

      that's awesome! I got a 1 lol. yay me, and yay huck! :D
Re^2: perl and apache2 on ubuntu 17.04
by hippo (Archbishop) on Jul 18, 2017 at 21:22 UTC
    sub an_exported_sub($$) {

    Can you explain why you are using the prototype? If not, remove it and try again.

      when i remove ($$) from the subroutine's declaration, and modify 'mytest.pl' to reflect those changes, i still get the exact same error. i tried an_exported_sub() and &an_exported_sub() and &an_exported_sub, all gave back the same results...no such sub.
      there is giant reason i use prototypes. but, i would like to know WHY it's such a giant deal that i do. many ask why. i can't see it mattering in the grand-scheme. but, to answer, i have LOTS of subs in many different modules. I cannot possibly recall what EVERY single one needs for params. This prototyping, at least, let's me know if i put in too many params, or not enough. nice and convenient. does it affect the issue at hand to leave it in? if not, then why even ask???
        there is giant reason i use prototypes. but, i would like to know WHY it's such a giant deal that i do.

        Please see Far More than Everything You've Ever Wanted to Know about Prototypes in Perl -- by Tom Christiansen. Just to briefly name a few issues, Prototypes do much more than just check how many arguments are passed to a function, they also affect how Perl code is parsed and how arguments are passed to functions (e.g. arrays are magically turned into arrayrefs where normally they would get flattened). If you have "lots of subs in many different modules", can you recall what the prototype of each and every one is? How about someone else using your code, or a future maintainer, will they be surprised at how their code gets parsed? Plus, just call a sub as &foo(...) and the prototype is ignored, and they're also not used for method calls.

        Note I'm not saying you shouldn't ever use them. But they're not really meant as a "check the number of arguments passed to a sub" feature, for that you've got @_==3 or croak "bad number of args to X", modules like Params::Validate, or even the experimental Signatures. Prototypes are best for functions that extend the Perl syntax (e.g. the way Try::Tiny does it), and if you do use them, you should be aware of all of the issues.