1 2 3 4 5
use Win32::TieRegistry; $Registry->Delimiter("/"); my $entries = $Registry->{"LMachine/System/CurrentControlSet/Control/TimeZoneInformation/"}; print $entries->{'/DaylightName'};
my $copy_ref = dclone( $original_ref );
1 2 3 4 5
my $entries = $Registry->{"HKEY_LOCAL_MACHINE/[...]/COUNTRIES_FOR_QUALITY/l1"}; my $copy_ref = dclone( $entries ); $entries->{'/V1'}=["other","REG_SZ"]; print $entries->{'/V1'}; print $copy_ref->{'/V1'};
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
#! /usr/bin/perl use strict; use warnings; use Storable qw( dclone ); my $hRef = { foo => { bar => 123, } }; my $copy = dclone( $hRef ); $hRef->{foo}->{bar} = 456; require Data::Dumper; print Data::Dumper->Dump( [ $hRef, $copy ], [ wq( *hRef *copy ], );
$copy = from_json(to_json($orig))
1 2
my $entries = $Registry->{"HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Control/Terminal Server/"}; $copy = from_json(to_json($entries));
Quoteencountered object 'Win32::TieRegistry=HASH(0x3f7adc)', but neither allow_blessed nor convert_blessed settings are enabled at test2.pl line 9
1 2 3
use JSON -convert_blessed_universally; $copy = from_json(to_json($entries, { allow_blessed => 1, convert_blessed => 1 }));
1 2 3 4 5
use Win32::TieRegistry; use JSON -convert_blessed_universally; $Registry->Delimiter("/"); my $entries = $Registry->{"HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Control/Terminal Server/"}; $copy = from_json(to_json($entries, { allow_blessed => 1, convert_blessed => 1 }));
1 2
my $hive = $Registry->{"HKEY_LOCAL_MACHINE/[...]/"}; my %hash_copy = %{$hive};
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#! /usr/bin/perl use Clone qw(clone); use Win32::TieRegistry; $Registry->Delimiter("/"); my $entries = $Registry->{"HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Control/Terminal Server/"}; my $copyOfEntries = clone($entries); print $entries->{'/SnapshotMonitors'}; print $copyOfEntries->{'/SnapshotMonitors'}; $entries->{'/SnapshotMonitors'} = ["2","REG_SZ"]; print $entries->{'/SnapshotMonitors'}; print $copyOfEntries->{'/SnapshotMonitors'}; $entries->{'/SnapshotMonitors'} = ["2","REG_SZ"];
$copy = new Win32::TieRegistry "LMachine";
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
sub my_clone { my $ref=shift; my $ret; my $type=ref($ref); if( $type eq 'ARRAY' ) { $ret=[]; for(@$ref) { push(@$ret,my_clone($_)); } } elsif( $type eq 'HASH' ) { $ret={}; while(my ($k,$v)=each(%$ref) ) { $ret->{$k}=my_clone($v); } } elsif($type) { die "Can't clone $type\n"; } # <= Nur Arrays und Hashes else { $ret="$ref"; } # <= um auch die letzten versteckten Objekte zu eleminieren return $ret; }
1 2
my $entries = $Registry->{"HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Control/Terminal Server/"}; my $copy = my_clone($entries);
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
sub my_clone { my $ref=shift; my $ret; my $type=ref($ref); if( $type eq 'ARRAY' ) { $ret=[]; for(@$ref) { push(@$ret,my_clone($_)); } } elsif( $type eq 'HASH' ) { $ret={}; while(my ($k,$v)=each(%$ref) ) { $ret->{$k}=my_clone($v); } } elsif($type eq 'Win32::TieRegistry') { $ret={}; while(my ($k,$v)=each(%$ref) ) { $ret->{$k}=my_clone($v); } } elsif($type) { die "Can't clone $type\n"; } else { $ret="$ref"; } # <= um auch die letzten versteckten Objekte zu eleminieren return $ret; }