jdporter has asked for the wisdom of the Perl Monks concerning the following question:
The doco saith:
Fields may optionally have initializing expressions. . . . the expression can . . . see any other variables in scope.class WithACounter { my $next_count = 1; field $count = $next_count++; }
But it doesn't say that any other kind of code can be present there. For example, maybe I'd like to do this:
class WithACounter { my $next_count = 1; if (last_one_was_bad()) { delete_last_one(); $next_count--; } field $count = $next_count++; }
Would that be permitted?
Also: it looks like the my variables there are essentially "class static" members — so called in other languages e.g. C#. Is that an accurate characterization?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: perl 5.38: can the body of a class declaration contain arbitrary code?
by haj (Vicar) on Jul 04, 2023 at 21:54 UTC | |
by jdporter (Paladin) on Jul 05, 2023 at 13:27 UTC | |
by haj (Vicar) on Jul 05, 2023 at 14:40 UTC | |
by jdporter (Paladin) on Jul 05, 2023 at 18:59 UTC | |
by haj (Vicar) on Jul 05, 2023 at 22:18 UTC | |
| |
|
Re: perl 5.38: can the body of a class declaration contain arbitrary code?
by parv (Parson) on Jul 04, 2023 at 21:11 UTC |