You are viewing a plain text version of this content. The canonical link for it is here.
Posted to embperl@perl.apache.org by jason n perkins <ja...@somebodydial911.com> on 2001/05/10 22:55:52 UTC

looking for a functin to move %fdat to the symbol table..

php has a function called extract which takes an array (no distinction
between arrays and hashes in php. in this case in perl, it'd actually be a
hash). extract takes the key values of the array (and optionally prepends a
user specified prefix to each of the values to avoid clobbering other values
in the symbol table), sets each of them up as a variable with that name and
sets the variable's value equal to the value of that associated key in the
hash. the beauty of extract comes into play when you want to use each of the
key/value pairs in the array. instead of setting them up one at a time, pass
the array to extract and voila, you have all of the key/value elements
available as variables. if my description is too unclear, you can check the
extract functions info at http://www.php.net/manual/en/function.extract.php.

does embedded perl sport a similar function?


:: jason n perkins
:: email -> jason@somebodydial911.com
:: web -> www.somebodydial911.com



---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org


Re: looking for a functin to move %fdat to the symbol table..

Posted by Kee Hinckley <na...@somewhere.com>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

At 3:55 PM -0500 5/10/01, jason n perkins wrote:
>hash). extract takes the key values of the array (and optionally prepends a
>user specified prefix to each of the values to avoid clobbering other values
>in the symbol table), sets each of them up as a variable with that name and
>sets the variable's value equal to the value of that associated key in the
>hash. the beauty of extract comes into play when you want to use each of the

This isn't going to gain you much.  It's the difference between:
	[+ $fdat{foo} +]
and
	[+ $foo +]

You could pretty easily write something like:
	foreach $key (keys %fdat) {
		eval("\$$key = '$fdat{$key}'")
...

That won't work as written, and of course you need to check for 
illegal variable names, reserved variables, characters that have to 
be escaped and the like.  And while you're at it you might want to 
change tab-seperated variables into arrays.  Embperl's hash is a bit 
more flexible because it doesn't have any of those restrictions, you 
just have to type 7 extra characters.

P.S. You'd probably also want to make %fdat contain references to the 
variables or vice versa, so that changing one would change the other. 
Otherwise you'll lose a lot of the magic of %fdat.
- -- 

Kee Hinckley - Somewhere.Com, LLC
http://consulting.somewhere.com/

I'm not sure which upsets me more: that people are so unwilling to accept
responsibility for their own actions, or that they are so eager to regulate
everyone else's.

-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>

iQA/AwUBOvsG5CZsPfdw+r2CEQLrJQCguJFmDe5mGbeu475V6n6WJnZKfdgAoIF1
9iF7G/ASs0bSpnX5PrhIfuUI
=TEqt
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org