Leser: 1
|< 1 2 >| | 12 Einträge, 2 Seiten |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use strict;
use Hash::Util qw(lock_keys);
my %hash = ();
$hash{Erlaubt} = 1;
$hash{Test} = 1;
$hash{Auch_erlaubt} = 1;
lock_keys(%hash);
sub foo {
my $h = shift;
$h->{uhu} = 1;
}
foo(\%hash);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#! /usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
use Hash::Util qw(lock_keys);
my %hash = (test => {key => 1, kes => 2},
test2 => {key => 1, kes => 2},
);
lock_keys(%{$hash{test2}});
$hash{test}->{uhu} = 1;
print Dumper(\%hash);
$hash{test2}->{uhu} = 1;
print Dumper(\%hash);
1
2
3
4
5
6
7
8
9
10
11
12
13
perl lock.pl
$VAR1 = {
'test2' => {
'kes' => 2,
'key' => 1
},
'test' => {
'uhu' => 1,
'kes' => 2,
'key' => 1
}
};
Attempt to access disallowed key 'uhu' in a restricted hash at lock.pl line 17.
1
2
3
4
5
6
7
8
use strict;
use Hash::Util qw(lock_keys);
my $hash = { uhu1 => 1 };
lock_keys(%$hash);
$hash->{uhu2} = 0;
^Z
Attempt to access disallowed key 'uhu2' in a restricted hash at - line 6.
sub lock_keys (\%;@)
|< 1 2 >| | 12 Einträge, 2 Seiten |