Thanks for the hint. What worked in the end was:-
%s =
(
qw( a 1 b 2 ),
"3", "3",
"4", "4",
);
which is about as terse and clear as I'd been hoping for.
Rgds, GStC.
PS: The Llama line is actually a correction to an earlier edition. Goodness
knows why it didn't work, but I don't think I'll bother with it any more...
-----Original Message-----
From: Paul Johnson [mailto:[EMAIL PROTECTED]
Sent: Friday, November 26, 2004 9:32 PM
To: Graeme St. Clair
Cc: '[EMAIL PROTECTED]'
Subject: Re: Adding to a Hash
On Fri, Nov 26, 2004 at 06:19:28PM -0800, Graeme St. Clair wrote:
> my %sname = qw {
> COUNTRY_NAME Country
> ...
> };
> my %words2 = (
> "ORDER_NUMBER", "Order Number",
> ...
> );
> #%sname{keys %words2} = values %words2; %sname = (%sname, %words2);
>
> I couldn't find a way to combine the whole assignment into any fewer
> statements, apart from the obvious way of double-quoting everything in
> sight, on the model of %words2. Moreover, the commented line was
> lifted straight out of the Llama book 2nd Ed p70, and gave a syntax
> error - the line below it works, but is described there as "much
> slower" than the commented line.
Either you have miscopied that line or there is an error in the Llama.
@sname{keys %words2} = values %words2;
> Any offers to improve the foregoing, other than what I've called "the
> obvious way"?
This, perhaps?
use Data::Dumper;
%s =
(
qw( a 1 b 2 ),
c => "3 3",
d => "4 4",
);
print Dumper \%s;
%t = ( e => 5 );
@t{keys %s} = values %s;
print Dumper \%t;
--
Paul Johnson - [EMAIL PROTECTED]
http://www.pjcj.net
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>