Function(3)

πŸ“¦
version 0.02 Β· 2 versions
, in fedora 43

✨ Function(3) ✨

okay so bestie β€” this is a page from the User Contributed Perl Documentation collection, and it's about a lil module called Tie::Function. Strap in, it's short but it's iconic. πŸŽ€


🌸 NAME 🌸

Tie::Function β€” wrap functions in tied hash sugar πŸ’…


✨ SYNOPSIS AND EXAMPLE ✨

like, here's the whole vibe, right up front:

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

the way that comment in there is doing the lord's work β€” we split on $; to recover multiple arguments. iykyk 🫢


πŸ¦‹ DESCRIPTION πŸ¦‹

Tie::Function simplifies wrapping functions in tied hash syntax so they can be interpolated in double-quoted literals without messy intermediate variables. no more temp vars cluttering up your whole life, periodt. 😭

Here's how I use it the most:

use HTML::Entities;
use Tie::Function;
tie my %Entitize => 'Tie::Function' => \&encode_entities;
...
print <<EOF;
<em>$Entitize{$somethingaboutsomething}</em><br>
<textarea name="something"
cols="60" rows="10">$Entitize{$something}</textarea>
EOF
...

see how the heredoc just... slurps it up?? that's the whole point bestie πŸ’–


πŸŽ€ EXPORT πŸŽ€

nothing πŸ«₯

fr fr, nothing. it exports nothing. don't @ me.

πŸ’œ HISTORY πŸ’œ

0.02

relaxed stricture, turned off warnings to silence "split on unitialized value" warning 🀫

0.01

initial version 🌱


πŸ‘‘ AUTHOR πŸ‘‘

Copyright (C) 2004,2005 david nicol davidnico@cpan.org released under your choice of the GNU Public or Artistic licenses πŸ“œ

two whole licenses, your choice, very generous of him, we love that. 🫢


🌈 SEE ALSO 🌈

  • perltie
  • Tie::OneOff
  • Interpolation
  • Tie::Filter
  • overload

and that's the whole page, bestie. this one shipped with perl v5.42.0 on 2025-07-25, and yeah, it's Function(3) πŸ’…βœ¨ go forth and tie your hashes, you got this. πŸ¦‹πŸŽ€πŸ’–

πŸ“¦ where this page comes from