I have wondered for some time, what a nice, clean solution for joining an array of strings might look like. Example: I have [\"Alpha\", \"Beta\", \"Gamma\"] and want to join
join() in Perl:
join()
use List::Util qw(reduce); sub mjoin($@) {$sep = shift; reduce {$a.$sep.$b} @_ or ''} say mjoin(', ', qw(Alpha Beta Gamma)); # Alpha, Beta, Gamma
Or without reduce:
reduce
sub mjoin($@) { my ($sep, $sum) = (shift, shift); $sum .= $sep.$_ for (@_); $sum or '' }