Hash::Extract - extract hash values onto lexical variables.


Hash-Extract documentation Contained in the Hash-Extract distribution.

Index


Code Index:

NAME

Top

Hash::Extract - extract hash values onto lexical variables.

VERSION

Top

Version 0.02

SYNOPSIS

Top

 use Hash::Extract qw(hash_extract);

 %hash = ( red => 'apple', blue => 'sky', );
 hash_extract( \%hash, my $blue );
 print $blue;  # ==> 'sky'

EXPORT

Top

This module can export one function.

FUNCTIONS

Top

hash_extract(\%hash, my $xxx, my $yyy);

extract value which is contained in hash into specified variable. hash key of that is same as variable name.

currently, you can use lexical variables declared in same scope as you call this function.



 hash_extract( $hashref, my $xxx);
 # ==> my $xxx = $hashref->{xxx};

 hash_extract( $hashref, our $xxx);
 # ==> die: could not detect name of variable.

note: in this version, hash_extract do not check value of arguments. but options may be added in future release. it is better that variables are set undefined.

AUTHOR

Top

YAMASHINA Hio, <hio at cpan.org>

BUGS

Top

Please report any bugs or feature requests to bug-hash-extract at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Hash-Extract. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

Top

You can find documentation for this module with the perldoc command.



    perldoc Hash::Extract

You can also look for information at:

* AnnoCPAN: Annotated CPAN documentation

http://annocpan.org/dist/Hash-Extract

* CPAN Ratings

http://cpanratings.perl.org/d/Hash-Extract

* RT: CPAN's request tracker

http://rt.cpan.org/NoAuth/Bugs.html?Dist=Hash-Extract

* Search CPAN

http://search.cpan.org/dist/Hash-Extract

SEE ALSO

Top

PadWalker

COPYRIGHT & LICENSE

Top


Hash-Extract documentation Contained in the Hash-Extract distribution.

## ----------------------------------------------------------------------------
#  Hash::Extract
# -----------------------------------------------------------------------------
# Mastering programmed by YAMASHINA Hio
#
# Copyright 2006 YAMASHINA Hio
# -----------------------------------------------------------------------------
# $Id: /perl/Hash-Extract/lib/Hash/Extract.pm 580 2007-12-19T06:29:03.536065Z hio  $
# -----------------------------------------------------------------------------
package Hash::Extract;
use strict;
use warnings;
use PadWalker qw(var_name);
use B;
use base 'Exporter';

our @EXPORT_OK = qw(hash_extract);
our %EXPORT_TAGS = (
	all => \@EXPORT_OK,
);

our $VERSION = '0.02';

1;

# -----------------------------------------------------------------------------
# hash_extract(\%hash, my $var);
# -----------------------------------------------------------------------------
sub hash_extract
{
	my $hash = shift;
	my $i=0;
	foreach my $var (@_)
	{
		my $name = var_name(1, \$var);
		$name or die "could not detect name of variable";
		{
		local(%+);
		$name =~ s/^\$//;# or die "argument is not scalar variable: $name";
		}
		exists($hash->{$name}) or die "no such hash element: $name";
		$var = $hash->{$name}
	}
}

# -----------------------------------------------------------------------------
# End of Module.
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
# End of File.
# -----------------------------------------------------------------------------
__END__