nysus has asked for the wisdom of the Perl Monks concerning the following question:

The following code snippet works fine when run out of the cgi-bin:
my $pdf = new PDF::Labels( $PDF::Labels::PageFormats[0], filename=>'files/labels.pdf', );
However, when I use this code from within subroutine in a package in my mod_perl application, I get the following error:
Can't use an undefined value as a symbol reference at /usr/local/share +/perl/5.20.2/PDF/Create.pm line 63.\n, referer: http://mydomain.com/i +ndex.pl
Not sure how to go about fixing this. I'm new to mod_perl.

$PM = "Perl Monk's";
$MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon";
$nysus = $PM . $MCF;
Click here if you love Perl Monks

Replies are listed 'Best First'.
Re: Can't use an undefined value as a symbol reference with mod_perl
by kennethk (Abbot) on Sep 24, 2015 at 15:38 UTC
    <shot in the dark>
    Try the code:
    my $pdf = PDF::Labels->new( $PDF::Labels::PageFormats[0], filename=>'files/labels.pdf', );
    Not quite sure why this might happen, but the error condition is saying that perl thinks you are trying to use something as a filehandle that doesn't have a value.
    </shot in the dark>

    It's also possible that the actual error is happening in the PDF::Labels new routine and someone is croaking it up to the invocation you are seeing. This would make sense, as you are passing in a filename, so maybe an open is failing and someone forgot to test it for success. That failure, in turn, could be due to a permissions problem, which could definitely result in a weird inconsistency between CGI and mod_perl.


    #11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

      OK, I changed the path to start from the root directory and that fixed the problem. So instead of files/labels.pdf I'm using /var/www/vt/files/labels.pdf. Thanks!

        That's a pathing problem rather than a permissions problem. It's probably worth figuring out what the mod_perl working directory is. Cwd


        #11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.