Re: Question about creating a hash of key-value pairs based on sub parameters.

2003-01-14 Thread Paul Johnson
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

Re: Question about creating a hash of key-value pairs based on sub parameters.

2003-01-14 Thread Ben Siders
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

Re: Question about creating a hash of key-value pairs based on sub parameters.

2003-01-14 Thread LRMK
[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, ...

RE: Question about creating a hash of key-value pairs based on sub parameters.

2003-01-14 Thread Dan Muey
> -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 > > "

Re: Question about creating a hash of key-value pairs based on sub parameters.

2003-01-14 Thread Rob Dixon
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 '%

Re: Question about creating a hash of key-value pairs based on sub parameters.

2003-01-14 Thread Rob Dixon
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

RE: Question about creating a hash of key-value pairs based on sub parameters.

2003-01-14 Thread Dan Muey
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

Question about creating a hash of key-value pairs based on sub parameters.

2003-01-14 Thread Ben Siders
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