in reply to Re: syntax error on foreach
in thread syntax error on foreach
You can only use a simple scalar variable as a foreach index.
However, there are ways to "subvert" this, if you're determined. Here are two possible scenarios (by no means they are perfect - there can be issues with dynamic scoping (local)).
If you don't need aliasing:
{ local $common::loaded{junk}; for (@modules) { $common::loaded{junk} = $_; # ... } }
If you need aliasing (requires Array::RefElem):
use Array::RefElem 'hv_store'; { local $common::loaded{junk}; for (@modules) { hv_store %common::loaded, 'junk', $_; # ... } }
Anyway, this is bad advice ;)
|
|---|