1Function(3)           User Contributed Perl Documentation          Function(3)
2
3
4

NAME

6       Tie::Function - wrap functions in tied hash sugar
7

SYNOPSIS AND EXAMPLE

9         use Tie::Function 0.01;
10         tie my %a, Tie::Function => sub{join '_'x$_[0],qw/( | )/};
11         print "small: $a{1}\nmedium: $a{2}\nwide: $a{3}\n";
12         # we split on $; to recover multiple arguments
13         tie my %times, Tie::Function => sub{
14               $_[0] * $_[1]
15         };
16         print "3 times 5 is $times{3,5}\n"
17

DESCRIPTION

19       Tie::Function simplifies wrapping functions in tied hash syntax so they
20       can be interpolated in double-quoted literals without messy
21       intermediate variables.
22
23       Here's how I use it the most:
24
25          use HTML::Entities;
26          use Tie::Function;
27          tie my %Entitize => 'Tie::Function' => \&encode_entities;
28          ...
29          print <<EOF;
30          <em>$Entitize{$somethingaboutsomething}</em><br>
31          <textarea name="something"
32          cols="60" rows="10">$Entitize{$something}</textarea>
33          EOF
34          ...
35

EXPORT

37       nothing
38

HISTORY

40   0.01
41       initial version
42
43   0.02
44       relaxed stricture, turned off warnings to silence "split on unitialized
45       value" warning
46

AUTHOR

48       Copyright (C) 2004,2005 david nicol davidnico@cpan.org released under
49       your choice of the GNU Public or Artistic licenses
50

SEE ALSO

52       perltie
53
54       Tie::OneOff
55
56       Interpolation
57
58       Tie::Filter
59
60       overload
61
62
63
64perl v5.34.0                      2022-01-21                       Function(3)
Impressum