Please try to give me a sub "newjoin" which croaks about this error!
It is, unfortunately, impossible.
You can get pretty close with some runtime heuristics. It's unlikely that people will often deliberately try to join a single-element list using a number as the delimiter, so:
sub newjoin ($@) {
my $delim = shift;
if (@_ == 1 and $delim =~ /^\d+$/) {
carp "Did you mean to put those parameters the other way round
+?";
}
return join $delim, @_;
}
Whether that will extend to other functions is, of course, highly dependent on their specific signatures.
I agree with you that it would be nice to have a robust general solution here, but it would seem to be quite a complicated thing to arrange for what could be fairly small gains in practice, and then you have to consider the risk of breaking existing code if you go round messing with how fundamental builtins like join() parse their arguments!