[VPM] programmically create keys and vals for anonhash

Peter Scott Peter at PSDT.com
Mon Feb 12 10:04:27 PST 2007


At 03:27 PM 2/11/2007, Jer A wrote:
>how do i programmically create a hash ref, without having to code the
>key and value pairs?
>eg.  $data = {Key1 => $val1,Key2 => $val2,Key3 => $val3} ;
>suppose I create an Array with key and value pairs,....the number of
>keys and values are only known at run time.
>eg.
>push(@HEADERS,{ KEYNAME => $1, KEYVAL => $2});

                ^ makes hashref              ^

>With the information in @HEADERS, how do I use this to create a
>hashref, with as many key/val pairs in the array, without manually
>coding it?
>
>$data = { "KEY" => "VAL", ... etc };

So @HEADERS contains hashrefs and you want to flatten them into a 
hashref containing all of their contents, is that it?

$data = { map %$_, @HEADERS };

-- 
Peter Scott
Pacific Systems Design Technologies
http://www.perldebugged.com/
http://www.perlmedic.com/



More information about the Victoria-pm mailing list