Next | The Perl Hardware Store | DC.pm Version | 61 |
The syntax actually looks like this:
use Interpolation '$' => \¤cy, q => \"e_for_CSV, Cap => sub { ucfirst lc $_[0] }, HTML=> \&html_escape;
$PROFITS = ($earnings - $expenses)/100; $state = "maryland"; $s = "$${$PROFITS} in the state of $Cap{$state}";
$104,254.12 in the state of Maryland
$data = 'Cleveland, "Ohio"'; $t .= qq{The data are: $q{$data}.};
The data are: "Cleveland, \"Ohio\""
$text = "x --> y"; print qq{<a href="move.cgi?x,y">$HTML{$text}</a>};
# .... x --> y ....
Prevents cluttering of code with lost of calls to formatting functions
Attention focused on output rather than on formatting code
Define formatters with mnemonic names like $currency or $Cap.
Clever hack:
use Interpolation 's' => 'sprintf1';
print "Profits were up by $s{'%2.2f',$amt} percent.\n";
Inserts sprintf call into a quoted string.
Next | Copyright © 2003 M. J. Dominus |