jason n perkins wrote:
> 
> 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?
> 

%fdat = qw(var1 2 var2 4); 
map { eval qq(\$$_ = \$fdat{$_}) } keys %fdat; 
print join(qq(\n), $var1, $var2, undef)

You could roll your own extract() with line 2, but
if you want to put it in a module, you might have to
make it smarter about what package its extracting into
with a call to caller().

-- Josh
_________________________________________________________________
Joshua Chamas                           Chamas Enterprises Inc.
NodeWorks >> free web link monitoring   Huntington Beach, CA  USA 
http://www.nodeworks.com                1-714-625-4051

Reply via email to