Help for this page

Select Code to Download


  1. or download this
    $phrase = 'Hello $dolly!';
    $variables = { dolly => 'Nurse' };
    
  2. or download this
        $phrase =~ s/\$([a-zA-Z0-9_]+)/$variables->{$1}/g;
        # also process variables in $(var_name) format.
        $phrase =~ s/\$\(([a-zA-Z0-9_]+)\)/$variables->{$1}/g;
    
  3. or download this
    $phrase = '$foo $bar';
    $variables = { foo => '$(bar)', bar => '$(foo)', };
    
  4. or download this
    my @phrase_parts = split /(\$(?:\(\w+\)|\w+))/, $phrase;
    foreach my $part ( @phrase_parts ) {
    ...
        || $part =~ s{ \$ \( (\w+) \) }{$variables->{$1}}xms;
    }
    $phrase = join '', @phrase_parts;