in reply to Re: set proto string
in thread set proto string
First of all using a closure variable my @a is also possible in your example if it's in the same scope like sub FETCH
Now provided that the package is an extra file, hence foreign scope, you can still pass arguments to the tie command, like a ref to \@a.
See tie VARIABLE,CLASSNAME,LIST
> Any additional arguments in the LIST are passed to the appropriate constructor method for that class--meaning TIESCALAR() , ...
But for flexibility and reusability I'd rather pass a coderef in LIST which acts as FETCH and returns the string.
FETCH would access the coderef as an attribute of $self
Hence for a package MyFetch tie $magic, MyFetch, sub { "@a 1,2" } would do and the numbers of closure variables would be totally free.
That's the beauty of functional programming. :)
Cheers Rolf
(addicted to the Perl Programming Language :)
see Wikisyntax for the Monastery
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: set proto string
by cavac (Prior) on Aug 18, 2024 at 00:04 UTC |