: "Ben Morrow" <
[email protected]> a écrit dans le message de :
[email protected]...
: > > Or is there a way to access the caller's function local variables ?
: >
: > Why do you want to do this? There is almost certainly a better way.
: >
: Has you saw in my previous post, I'm trying to "localize" my application
: (ie support different languages). I took a look at Locale::Maketext but it
: seems
: to complex to use and require additionnal packages.
Life is like that sometimes. If you want something done right, you'll have
to work at it.
: So I thought to write a simple module which will do what I want :
:
: The idea is to have a text file for each language (or a simple hash) like:
: id1: the text associated to id1 with $variableA
:
: And also I will have a function:
:
: sub my_gettext {
: my ($id) = @_
: return eval "return \"$localized{$id}\"";
: }
:
: where localized is a hash associated to the configuration file
: This would work when variable are not localized with "my" ...
Then don't use such lexical variables to store information needed by the
subroutine.
: But to be "cleaner" I would like it to work in anycases
That's just wrong thinking. Prying open a foreign lexical scope is useful
for debugging or in cases of dire emergency, but doing it in real
production code is an _appallingly_ bad idea. The code will certainly not
be clean.
: for that I need to access the caller's localized variables or use macros
: But the main idea is to keep it simple ...
The simple solution would be to use package variables when you need to
access them from somewhere else. That's the whole reason why package
variables exist.
For a recent discussion of I18N techniques, see the thread starting at
Message-ID: <
[email protected]>