How do you use dual-life modules with a short example?

Perl's dual-life modules allow you to use the same API for both Perl and XS (C) versions of a module, depending on your use case. This is especially useful when certain functionalities are only available in the XS version, while still providing a pure Perl implementation as a fallback.

Here’s a simple example to demonstrate how to use dual-life modules in Perl:

#!/usr/bin/perl use strict; use warnings; # Importing the dual-life module use List::Util qw(sum); my @numbers = (1, 2, 3, 4, 5); # Using the sum function from List::Util my $total = sum(@numbers); print "The sum of the numbers is $total\n";

Perl dual-life modules List::Util XS C programming