Ben Siders said:
> This is perfect. The input is coming from a CPAN module so I'm fairly
> confident that the number of entries will be even, but checking is
> always a good idea.
If you have warnings on, Perl will whine if it's not.
>>You may want to check first that the list has an even numb
This is perfect. The input is coming from a CPAN module so I'm fairly
confident that the number of entries will be even, but checking is
always a good idea.
You may want to check first that the list has an even number of entries:
die "Invalid parameters" if @_ % 2;
but after that it's just
[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, January 14, 2003 10:57 PM
Subject: Question about creating a hash of key-value pairs based on sub
parameters.
> I have a subroutine that will receive parameters as follows:
>
> key1, value1, key2, value2, key3, value3, ...
> -Original Message-
> From: Rob Dixon [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, January 14, 2003 11:17 AM
> To: [EMAIL PROTECTED]
> Subject: Re: Question about creating a hash of key-value
> pairs based on sub parameters.
>
>
> Dan
>
> "
Dan
"Dan Muey" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> This may work :
>
> &monkey("key","value","key1","value1");
>
> sub monkey {
> %new_hash = ();
> %new_hash = $_[0];
$_[0] is 'key', so this will assign %new_hash = ( key => undef );
You want '%
Hi Ben
"Ben Siders" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> I have a subroutine that will receive parameters as follows:
>
> key1, value1, key2, value2, key3, value3, ... keyN, valueN
>
> I want to create a hash of key1 => value1, key2 => value2, ... , k
day, January 14, 2003 10:57 AM
> To: [EMAIL PROTECTED]
> Subject: Question about creating a hash of key-value pairs
> based on sub parameters.
>
>
> I have a subroutine that will receive parameters as follows:
>
> key1, value1, key2, value2, key3, value3, ... keyN, valueN
I have a subroutine that will receive parameters as follows:
key1, value1, key2, value2, key3, value3, ... keyN, valueN
I want to create a hash of key1 => value1, key2 => value2, ... , keyN =>
valueN in the subroutine. I'm curious if there's a Perl "trick" to
doing this beyond the obvious loop