in reply to regex substitution
my $rhChildren = { {'Peter'} => { child_name => 'Peter', teacher_name => 'Ms. Jones', room_number => '503' } }; #add records as needed my $text = "Your child #child_name# is invited to come to our school. +Your child's teacher will be #teacher_name#, and the class is held in + room #room_number."; foreach my $child (keys %$rhChildren) { my $substText; ($substText = $text) =~ s/\#([^#]+)\#/$rhChildren->{$child}{$1}/g; print "$substText\n"; }
OK, so there is a redundancy in using the child's name both as key and value in the hash, but it works and uses regexes, right?
|
|---|