[VPM] programmically create keys and vals for anonhash

Abram Hindle abez at abez.ca
Sun Feb 11 15:39:20 PST 2007


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

You can convert an array or list to hash just by assigning it:

%hash = qw( key1 value1 key2 value2 key3 value3);

Hashes can be formed from lists and array of an even number of elements
where keys and values alternate.

	$hash{$1} = $2; #works

	push @headers,$1,$2; #works
	...
	%hash = @headers;
	
see perldoc perldsc

abram

Jer A (by way of Darren Duncan) wrote:
> Darren is redirecting this to the list, as my own probe succeeded.
> ------------------
> 
> Hello Darren, I am resending you this message directly, as there is 
> something wrong with the perl mailing-list.
> 
> -------------------
> Hi All,
> 
> 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});
> 
> 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 };
> 
> 
> Thanks in advance for your help.
> 
> -Jer A.
> _______________________________________________
> Victoria-pm mailing list
> Victoria-pm at pm.org
> http://mail.pm.org/mailman/listinfo/victoria-pm
> 
>  
>  ** ACCEPT: CRM114 PASS osb unique microgroom Matcher ** 
> CLASSIFY succeeds; success probability: 1.0000  pR: 34.7366
> Best match to file #0 (/home/abez/crm/nonspam.css) prob: 1.0000  pR: 34.7366  
> Total features in input file: 3312
> #0 (/home/abez/crm/nonspam.css): features: 378059, hits: 4066312, prob: 1.00e+00, pR:  34.74 
> #1 (/home/abez/crm/spam.css): features: 2082284, hits: 3381458, prob: 1.83e-35, pR: -34.74 
>  

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.4 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFz6konOrfa1yW8IURApEOAKCowGUmzAUgsc9FzOVy3nSstE4H8wCggIz/
RZQKC2JTRJpTQ/87wSVrmXo=
=RX5T
-----END PGP SIGNATURE-----


More information about the Victoria-pm mailing list