in reply to Re^4: PDF::API2::Simple - pass parameter to header
in thread PDF::API2::Simple - pass parameter to header

No. That can't work. That's also not what I showed. You will need to supply that parameter yourself, outside of the "parameters". A subroutine reference never takes parameters. Maybe something like the following:

my $pdf = PDF::API2::Simple->new( header => \&my_header($CategoryName), footer => \&footer, margin_left => 15, margin_top => 15, margin_right => 15, margin_bottom => 45 ); sub my_header { my $pdf = shift; my $cat = $CategoryName; print $cat; header($pdf); } sub header { my $pdf = shift; # do my stuff }

... or, alternatively, if your $CategoryName changes several times before your (different) PDF objects output themselves, you can create the subroutines anonymously on the fly:

my $pdf = PDF::API2::Simple->new( header => sub { my_header($CategoryName), }, footer => \&footer, margin_left => 15, margin_top => 15, margin_right => 15, margin_bottom => 45 ); sub header { my $pdf = shift; # do my stuff }

Replies are listed 'Best First'.
Re^6: PDF::API2::Simple - pass parameter to header
by constantin.iliescu (Initiate) on Mar 12, 2010 at 09:56 UTC
    Thanks, Corion! I tried your suggestions. The first one can't work because the category name is changes in a loop I make after defining the pdf object. The second one gave the same 'not a code reference...' error. I placed a variable outside the fuctions which I set in my first function and use in the header function. Thanks you very much!