Farid Hajji: Perl - Einführung, Anwendungen, Referenz
2., aktualisierte und erweiterte Auflage
Addison-Wesley Longman, ISBN 3-8273-1535-2
tie-refhash.pl
#!/usr/local/bin/perl -w
# tie-refhash.pl -- Referenzen als Schluessel in Hashes
use Tie::RefHash; # Standardmodul
use strict 'refs'; # Keine symbolische Referenzen!
$node = { VALUE => 'xyzzy' };
$changeme = "change me!";
tie %ts, 'Tie::RefHash';
$ts{ [] } = "The Array";
$ts{ {} } = "The Hash";
$ts{ \substr($changeme, 0, 6) } = "An lvalue!";
$ts{ sub { exit 0; } } = "Anonymous subroutine!";
$ts{ \*STDIN } = "This is stdin!";
$ts{ $node } = "VISITED";
$ts{ \@ARGV } = 'This is Array @ARGV!';
while (($key,$val) = each %ts) {
print "Found: $key",
", Type: " , ref($key),
", Value: ", $val, "\n";
push(@{$key}, qw(not empty anymore)) if $val eq 'The Array';
$key->{'firstkey'} = 'first value' if $val eq 'The Hash';
${$key} = 'try' if $val eq 'An lvalue!';
print "node visited...\n" if $key == $node
and
exists $key->{'VISITED'};
}
print "new changeme: >$changeme<\n";
use Data::Dumper;
print Dumper(grep { ref($_) ne 'LVALUE' } keys %ts);
untie %ts;
[Prev] [Up] [Relevant Chapter] [Next]
[Alte Quelle]
| Last modified: $Date: 2006/05/18 12:56:09 $ FH. Search :: Sitemap :: Disclaimer :: Copyright :: Privacy |
|