note
Fletch
<p>
Had a reeeeeaaaaly vague recollection and the <a href="https://learning.oreilly.com/library/view/perl-cookbook-2nd/0596003137/"><i>Perl Cookbook</i></a> (Ch 1 section 19) does actually offer <c>$_ = join(' ', split(' '));</c> as an alternative to these three substitutions:
</p>
<c>
s/^\s+//;
s/\s+$//;
s/\s+/ /g;
</c>
<p>
to strip and canonicalize to single spaces; and does offer this <c>trim</c> sub:
</p>
<c>
sub trim {
my @out = @_ ? @_ : $_;
$_ = join(' ', split(' ')) for @out;
return wantarray ? @out : "@out";
}
</c>
<p>
<b>Edit:</b> That being said, I don't recall having seen this construct in the wild otherwise and had the vaguest of hunches that <i>PC</i> mentioned anything like this so I'd hardly call it a "common idiom" either.
</p>
<div class="pmsig"><div class="pmsig-58196">
<p>
The cake is a lie.<br />
The cake is a lie.<br />
The cake is a lie.<br />
</p>
</div></div>
11121538
11121800