in reply to Computed "my" declarations?
You'll have to use code generation. The result is that you get a subroutine that's hard-coded to use a list of stuff and you just change how it compiles if you need to alter it. I included a #line declaration so the compilation errors, if any, would come out on the right line.
package Foo::Bar; BEGIN { my @attributes = qw( ... ); eval '#line ' . (1+__LINE__) . ' "' . __FILE __ . '" sub ... { ... my ( ' . join( ', ', map { "\$$_" } @attributes ) . ' ) = @{$self}{qw(' . join( ' ', @attributes ) . ')}; ... }'; die $@ if $@; }
This node has been updated to fix some minor bugs including the omission of the elipses after the my declaration. This mistake on my part confused someone about my intentions. I did not intend to indicate that the subroutine had no more statements in it.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Computed "my" declarations?
by Tanktalus (Canon) on Oct 26, 2005 at 23:23 UTC | |
by diotalevi (Canon) on Oct 26, 2005 at 23:28 UTC |