Don't ask to ask, just ask | |
PerlMonks |
Re: Joining elements of an array in a hashby kcott (Archbishop) |
on Mar 26, 2017 at 21:58 UTC ( [id://1186014]=note: print w/replies, xml ) | Need Help?? |
G'day orangepeel1, It's unclear whether you want to join all the elements into a single string, or join the elements from each key into separate strings. It's also unclear what your ultimate goal is: to use the joined strings in subsequent processing; print them immediately; save them in a file; something else. To get the best answers, it generally helps to provide an overall picture of what you want to achieve (see "XY Problem" for a more detailed discussion of this). There's two "Special Variables" you could potentially use: '$,' (the output field separator); '$"' (the list separator). The following script shows the use of these special variables, for immediate printing or assignment to variables, for both the single and multiple string options. Note the use of the outer anonymous blocks, and the local function, to localise the changes to the special variables; also the inner anonymous blocks to keep the two $statement variables totally separate. [Aside: You should generally avoid using the same variable name (e.g. $statement) in the same block of code. I've only done it here for illustrative purposes and to retain the variable name you originally used. Whenever you have a genuine reason for using the same name, I'd strongly recommend keeping them separate with anonymous blocks (as I've shown here). In actual fact, without those anonymous blocks, in the code as written, those variables would still be separate; however, at some later point, when a change is made, one could possibly affect the other — with the anonymous blocks, that won't happen.]
Output:
— Ken
In Section
Seekers of Perl Wisdom
|
|