in reply to Algebraic Hash Configuration via Delayed Closure?

My first idea was to pass in the width/height:
my $g = Games::Grid->new( border => 4, width => sub { $_[0]/4 }, height => sub { $_[0] }, fill => '=', ); { my $W = $self->{terminal}->{_co}; my $H = $self->{terminal}->{_li}; $self->terminal->{WIDTH} = $config{width}->($W); $self->terminal->{HEIGHT} = $config{height}->($H); }
I suspect that may not be flexible enough to meet your needs, though...

How about using package variables for $W and $H, instead of lexical variables?

my $g = Games::Grid->new( border => 4, width => sub { $terminal::W/4 }, height => sub { $terminal::H }, fill => '=', ); { $terminal::W = $self->{terminal}->{_co}; $terminal::H = $self->{terminal}->{_li}; $self->terminal->{WIDTH} = $config{width}->(); $self->terminal->{HEIGHT} = $config{height}->(); }

Replies are listed 'Best First'.
Re: Re: Algebraic Hash Configuration via Delayed Closure?
by princepawn (Parson) on Mar 07, 2001 at 01:02 UTC
    Actually, the way to delay the evaluation of the closure is to put it in single quotes and then eval() it when you have placed $W and $H into scope.

    It always helps to see other people's input on these problems as I turn it over in my head.

      Oh, please don't use eval() for that. That's not a smart reason to use eval(). There are better ways to approach the problem, as have been shown.

      japhy -- Perl and Regex Hacker