Use a translation table (hash):
use strict; use warnings; my $string="A111B111A111B111"; my $yes_or_no="no"; my %decision = ( A => 'yes', B=> 'no' ); for (split //, $string ) { $yes_or_no = $decision{$_} if exists $decision{$_}; print "$_ ($yes_or_no)\n"; }
In reply to Re: Change variable multiple times within a single string?
by hdb
in thread Change variable multiple times within a single string?
by JTomb
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |