perl -I$HOME/perl5/lib/perl5 -Mlocal::lib prints out some shell code. The point of
eval $(…) is to execute that code in the context of the current shell. This is typically used to set environment variables. You can't use a subprocess for this as this would only affect the subprocess's environment. You can source a snippet:
but that only works if the code that generates the variable values is written in shell. Here that code is written in Perl, so the Perl code generates shell code.
dircolors uses the same technique, as do many other programs.
The shell snippets are generally kept very simple, just variable assignments (with plain strings for values) and
export statements, so they are compatible with all Bourne-style shells (including any POSIX shell) and zsh.
local::lib is gratuitously incompatible with some decade-old systems as it combines
export with assignment (which is permitted by POSIX but not by the original Bourne shell). Csh requires a different syntax; local::lib emits csh syntax if
csh as a substring. Under Windows, local::lib generates the equivalent cmd syntax; because cmd has no equivalent .