Perl's join() ignores (skips) empty array values; PHP's implode() does not appear to.
Suppose I have an array:
$array = array('one', '', '', 'four', '', 'six');
implode('-', $array);
yields:
one---four--six
instead of (IMHO the preferable):
one-four-six
Any other built-ins with the behaviour I'm looking for? Or is it going to be a custom jobbie?
joindoesn't skip undefined elements. In fact, they result in a warning.$a[0]="a"; $a[2]="c"; say join "-",@a;displaysUse of uninitialized value within @a in join or stringanda--c. One can usejoin '-', grep !defined, ...to skip undefined values.grep !length,will do empty strings.