I often use join but it can begin to get tedious if, for instance, you are printing more than one array using the same separator. Localising a change to the list separator then begins to simplify things, as in this rather contrived and silly example.
use strict;
use warnings;
my @ladies = qw{ ann flo jen };
my @gents = qw{ bob pip tim };
print
q{The ladies, (},
join( q{, }, @ladies ),
q{), met the gents, (},
join( q{, }, @gents ),
qq{).\n};
print
qq{The ladies, (@{ [ join q{, }, @ladies ] }), },
qq{liked the gents, (@{ [ join q{, }, @gents ] }).\n};
print do{
local $" = q{, };
qq{The ladies, (@ladies), married the gents, (@gents).\n};
};
The ladies, (ann, flo, jen), met the gents, (bob, pip, tim).
The ladies, (ann, flo, jen), liked the gents, (bob, pip, tim).
The ladies, (ann, flo, jen), married the gents, (bob, pip, tim).
Cheers, JohnGG |