in reply to Re^4: Concatenate printing a string and array
in thread Concatenate printing a string and array
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: Concatenate printing a string and array
by AnomalousMonk (Archbishop) on Jan 07, 2009 at 04:23 UTC |