How has support for given/when (smartmatch ~~, experimental) changed across recent Perl versions?

The support for the given/when (smartmatch) feature in Perl has evolved significantly through recent versions. Initially introduced as an experimental feature, it has been subject to various changes and discussions within the Perl community regarding its usage and reliability.

In earlier versions, smartmatch was versatile, allowing comparisons between different types of data structures, leading to some unexpected behavior. Over time, Perl's development team recognized these inconsistencies, leading to the deprecation of smartmatch in more recent versions.

As of Perl 5.24, the feature is still available, but with a word of caution due to its unpredictable nature. Users are encouraged to use more explicit methods for data comparison, such as 'eq', '==', or using the List::Util module for better clarity.

Here's an example illustrating basic usage of the given/when feature:

# Example of using 'given/when' (smartmatch) use 5.10.0; # Enable given/when my $value = 'apple'; given ($value) { when ('banana') { say 'This is a banana.'; } when ('apple') { say 'This is an apple.'; } when ('orange') { say 'This is an orange.'; } default { say 'Unknown fruit.'; } }

perl given when smartmatch experimental feature