http://qs1969.pair.com?node_id=280921

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

Hi All,

I have written a multipage CGI script using the technique described in recipe 19.12 of the Perl Cook book. Namely put all the HTML generation/program logic in subroutines and store those subs as values of a hash.

This all works fine until you need to pass an argument when declairing the code ref within the hash. When this is done the subroutine is executed (I assume this has to be done because the sub has to be exaluated because of the arg).

This totally breaks my multipage CGI script as one page is only ever displayed. How do I fix this?

Here is an example that demonstrates the problem:

sub print_me { my $arg = shift || "Hello World!\n"; print $arg; } %hash = {no_arg => \&print_me, with_arg => \&print_me("Hello World, again!\n" }; $hash{no_arg}->();

__OUTPUT__

Hello World, again!\n";

I'm using Perl 5.6.1 on Linux

!unlike

I write my Perl code like how I like my sex: fast and dirty. ;)