Rodster001 : ($names is an arrayref of hashes)I guess you mean an arrayref of hashrefs.
I'd really like to do it in one (line), without the foreachWhy without the foreach? you can do in in one line with a foreach and without having to use an intermediate temporary array. For example:
Note that I have added a space after the comma because I find it visually better when printing it; just remove that space if you don't want it.my $id = ""; $id .= "$_->{id}, " foreach @$names;
Having said that about foreach, I must say that I would rather use a map for this problem:
or, taking into account Athanasius's judicious comment:my $id = join ", ", map $_->{id}, @$names;
Also note that I have used for the map a syntax different from that used by the previous monks, this is just just for the sake of illustrating this alternate syntax.my $id = join ", ", map $_->{id} // (), @$names;
In reply to Re: Joining the hash values of an array of hashes
by Laurent_R
in thread Joining the hash values of an array of hashes
by Rodster001
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |