#! perl -slw use strict; use vars qw[ $LANG ]; BEGIN{ $LANG ||= 'ENGLISH'; } use Language $LANG; print RED, GREEN, BLUE; print "The RED ballon floated over the GREEN fields in the BLUE sky"; { no Language; print RED, GREEN, BLUE; print "The RED ballon floated over the GREEN fields in the BLUE sky"; } print RED, GREEN, BLUE; print "The RED ballon floated over the GREEN fields in the BLUE sky"; __END__ P:\test>junk redgreenblue The red ballon floated over the green fields in the blue sky redgreenblue The RED ballon floated over the GREEN fields in the BLUE sky redgreenblue The red ballon floated over the green fields in the blue sky P:\test>junk -LANG=DUTCH roodgroenblauw The rood ballon floated over the groen fields in the blauw sky roodgroenblauw The RED ballon floated over the GREEN fields in the BLUE sky roodgroenblauw The rood ballon floated over the groen fields in the blauw sky P:\test>junk -LANG=FRENCH rougevertbleu The rouge ballon floated over the vert fields in the bleu sky rougevertbleu The RED ballon floated over the GREEN fields in the BLUE sky rougevertbleu The rouge ballon floated over the vert fields in the bleu sky #### package Language; use Inline::Files; use strict; use overload; my %words; sub import { no strict 'refs'; my $caller = caller; my( $class, $lang ) = @_; $lang = uc $lang; my $fh = \*{$lang}; while( <$fh> ) { my( $english, $trans ) = m[(\w+)\s*=\s*(\w+)]; $words{ $english } = $trans; eval qq[ # line 1 "Language::import" *${caller}::$english = bless sub() { '$trans' }, '$class'; ]; } overload::constant ( q => \&interp ); } sub unimport { overload::remove_constant ( q => \&interp ); } sub interp{ my( $orig, $perl, $use) = @_; $orig =~ s[\b([A-Z]+)\b]{ exists $words{ $1 } ? $words{ $1 } : $1 }ge; $orig; } 1; __ENGLISH__ RED = red BLUE = blue GREEN = green __FRENCH__ RED = rouge BLUE = bleu GREEN = vert __DUTCH__ RED = rood BLUE = blauw GREEN = groen