In case you're also wondering more generally why it's possible to assign something to a function, the answer is that it is an "lvalue" sub. Another notable example of such a function is substr:
my $foo = "Hello, World!";
substr($foo,7,5) = "PerlMonks";
print "$foo\n";
__END__
Hello, PerlMonks!
You can even write Lvalue subroutines yourself:
my $value;
sub foo : lvalue {
$value
}
foo() = "Bar";
print "$value\n";
__END__
Bar
However, at least in my experience, they're only really useful in a few rare circumstances. |