Leser: 1
9 Einträge, 1 Seite |
1
2
3
4
5
6
7
8
9
10
11
my %hash = (
"name" => "lucas"
);
my $res = get_key("lucas");
sub get_key {
foreach (my ($key, $value) = each(%hash)) {
return "$key\n" and last if $value eq $_[0];
}
}
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
$xpvhv = {
array => [
{
next => {
next => {
next => {
# usw
},
hek => 'key3',
val => 'value3',
},
hek => 'key2',
val => 'value2',
},
hek => 'key',
val => 'value',
},
{
next => {
# usw
},
hek => 'key',
val => 'value',
},
],
# magische felder fuer iterator, index, stash etc.
};
1
2
3
4
5
6
7
#!/usr/bin/perl
use warnings;
use Data::Dumper;
use strict;
my %a = (a => 'b', c => [qw/user1 user2 user3/], e => 'f');
my %b = reverse %a;
print Dumper(\%b);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
use strict;
use warnings;
my %hash = (
foo => "bar",
bar => "baz",
baz => "bar"
);
print join ", ", find_key( \%hash, 'bar' );
print "\n";
sub find_key {
my ( $hash, $val ) = @_;
grep { $$hash{$_} eq $val } keys %$hash;
}
9 Einträge, 1 Seite |