in reply to Change variable multiple times within a single string?
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"; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Change variable multiple times within a single string?
by 2teez (Vicar) on Apr 27, 2013 at 15:35 UTC | |
by hdb (Monsignor) on Apr 27, 2013 at 16:38 UTC | |
by 2teez (Vicar) on Apr 27, 2013 at 18:09 UTC |
In Section
Seekers of Perl Wisdom