rgbcof
asked on
perl, advanced text substitution
%hash = (YEAR_95 => '1st daughter', YEAR_97 => '2nd daughter', YEAR_99 => '1st son');
$string = "First YEAR_95, then YEAR_97, then YEAR_99";
How to substitute pattern YEAR_nn in the string with the hash value?
So that the result is: "First 1st daughter, then 2nd daughter, then 1st son";
$string = "First YEAR_95, then YEAR_97, then YEAR_99";
How to substitute pattern YEAR_nn in the string with the hash value?
So that the result is: "First 1st daughter, then 2nd daughter, then 1st son";
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
print "First $hash{'YEAR_95'}, then $hash{'YEAR_97'}, then $hash{'YEAR_99'}\n";
$string=~/(YEAR_\d\d)/$has h{$1}/g;
$string=~s/(YEAR_\d\d)/$ha sh{$1}/g;
ASKER