in reply to Small examples of string eval
The one thing where eval is basically unavoidable is the use of a string variable within the "tr///" operator. It's simple, basic, and has a bunch of obvious uses in "real-life".
(update: forgot to include an example...)
my %charmap = ( a => 'B', c => 'D', ) # ... could come from a config f +ile my $old = join '', keys %charmap; my $new = join '', values %charmap; while (<>) { eval "tr{$old}{$new}"; if ( $@ ) { die "tr{$old}{$new} failed at line $.: $_"; } print; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Small examples of string eval
by ikegami (Patriarch) on May 13, 2006 at 07:29 UTC | |
|
Re^2: Small examples of string eval
by spurperl (Priest) on May 13, 2006 at 07:28 UTC | |
by ikegami (Patriarch) on May 13, 2006 at 07:44 UTC |