[Pdx-pm] I think that I'm trying to make things too hard.

Austin Schutz tex at off.org
Wed Oct 25 20:24:27 PDT 2006


On Wed, Oct 25, 2006 at 08:19:24PM -0700, Michael G Schwern wrote:
> benh wrote:
> > So I'm building a small site for a client. Durring the process I
> > started playing with the idea that every page is a module, there are
> > some that just needed to be text, others that needed to do things.
> > Though, things didn't go as easily as I would have liked, and I ended
> > up going about things the longer way to make it all go. But I was
> > wondering if there was a cleaner/better way of doing this.
> > 
> > The crux of things is that I am attempting to use a var to call these
> > module/pages. So I was hopeing for something along the lines of:
> > 
> > my $action=CGI::param('action');
> > $data->{'body'}=local::$action::generate_page_data();
> > 
> > problem is that I get a 'bad name after local::' error.
> 
> no strict 'refs';
> $data->{body} = &{"local::$action::generate_page_data"};

	While this works, I tend to use {}s around variable names
to disambiguate them inside double quotes:

$data->{body} = &{"local::${action}::generate_page_data"};

or

$data->{body} = &{ 'local::' . $action . '::generate_page_data' };

that way you don't have to remember the precedence rules when/if
$action::generate_page_data is defined. But, ah, you're right about it
being something to generally avoid in the first place.

	Austin


More information about the Pdx-pm-list mailing list