princepawn has asked for the wisdom of the Perl Monks concerning the following question:
What this means is that the width of the game grid is 1/4 the value of $W, which should be bound to the terminal width. The height is equal to the terminal width. And the grid should be filled with equal signs.my $g = Games::Grid->new (border => 4, width => sub { $W/4}, height => sub { $H }, fill => +'=');
The following code in new:
is not working because the closure was evaluated as soon as I defined the hash and $W was not in its scope.{ my $W = $self->{terminal}->{_co}; my $H = $self->{terminal}->{_li}; $self->{terminal}->{WIDTH} = $config{width}->(); $self->{terminal}->{HEIGHT} = $config{height}->(); }
How can I delay the attempt to bind $W until I evaluate the closure within the constructor?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Algebraic Hash Configuration via Delayed Closure?
by btrott (Parson) on Mar 06, 2001 at 23:36 UTC | |
|
Re: Algebraic Hash Configuration via Delayed Closure?
by chipmunk (Parson) on Mar 06, 2001 at 23:37 UTC | |
by princepawn (Parson) on Mar 07, 2001 at 01:02 UTC | |
by japhy (Canon) on Mar 07, 2001 at 02:19 UTC | |
|
Re: Algebraic Hash Configuration via Delayed Closure?
by AgentM (Curate) on Mar 07, 2001 at 01:32 UTC | |
|