Next | Hook::LexWrap | 7 |
Function get_temp expects and returns temperatures in degrees Fahrenheit
We wanted Celsius instead
wrap 'get_temp', pre => sub { @_ = ($_[0] * 9/5 + 32) }, post => sub { $_[-1] = ($_[-1]-32) * 5/9 };
my $celsius = get_temp(100); # boiling point of water
Assigning to @_ in the prewrapper alters the arguments the function sees
Assigning to $_[-1] in the postwrapper alters the return value
Next | Copyright © 2003 M. J. Dominus |