in reply to Re^4: How do I pretend a reference isn't a reference
in thread How do I pretend a reference isn't a reference

Well yes, but isn't your use/implementation of map in the example just a for testing?

In your original example you had:

my @days = ( _('Mon'),_('Tues'),_('Wed'),_('Thurs'),_('Fri'),_('Sat'),_('Sun') );

So if your later example became

my @days = map _( $_ ), qw[ Mon Tue Wed Thu Fri Sat Sun ];

with all the choosing of packages and tieing hidden inside sub _{ ... }, then the translation will be done at runtime as required?


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

Replies are listed 'Best First'.
Re^6: How do I pretend a reference isn't a reference
by clinton (Priest) on Nov 06, 2008 at 11:52 UTC
    Well, my original example was defining the array @days at compile time, because that's going to be more efficient than:
    sub day_of_week { my $self = shift; my @days = _('Mon'),_('Tues'),_('Wed'),_('Thurs'),_('Fri') +,_('Sat'),_('Sun'); return $days[ $self->{day_num} ]; }

    To give another example, I have about 3,000 lines of YAML config data, which gets loaded into a hash during initialisation. Some of that data will contain strings-to-be-translated, eg:

    status: a: _('Active') i: _('Inactive')

    During init, I check all the scalar values in the config hash and, if they match the _('...') form, then I bless them into i18n::String. Doing this with tie wouldn't be feasible.

    Clint