Two examples, reduced to absurdity, follow...
EXAMPLE 1:
...such that if I later call...sub N_scalars { my ($prefix, $qty) = @_; ...unknown magic here... }
...it initializes five scalars as if I had done...N_scalars("foo",5);
EXAMPLE 2:$foo_1 = ''; $foo_2 = ''; $foo_3 = ''; $foo_4 = ''; $foo_5 = '';
...so that if I later call...sub arb_scalars { foreach $foo (@_) { ...unknown magic here... } }
...it works as if I had done...arb_scalars("alfa","bravo","charlie");
I know that looks ridiculous, but it is a useful way to automate other subs. I can do it in PostScript simply by converting a string to a variable. The real world use I am shooting for is more complicated. But if the above could be done, then I could also do what it is I have in mind. I could get around it with references, but the result would be unreadible a hundred lines further down the file. To use named scalars would be much preferable. But my sub, to be flexible, ought be fed a list of strings from which to create its vars.$alpha = ''; $bravo = ''; $charlie = '';
I'm guessing it might be impossible. Does anyone know?
Thanks,
Gan
update (broquaint): dropped <pre> tags and added formatting
In reply to create arbitrarily named scalars by aplonis
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |