Leser: 1
|< 1 2 >| | 12 Einträge, 2 Seiten |
1
2
3
4
5
my $sql = "INSERT INTO db (";
$sql .= join", ", keys( %{$ref} );
$sql .= ") VALUES ('";
$sql .= join", ",values( %{$ref} );
$sql .= "')";
1
2
3
4
5
6
%hash = ();
for (1..10) {
$hash{$_} = $_*$_;
}
print "keys: ", join " ", keys %hash, "\n", "values: ", join " ", values %hash;
QuoteReturns a list consisting of all the values of the named hash. (In a scalar context, returns the number of values.) The values are returned in an apparently random order. The actual random order is subject to change in future versions of perl, but it is guaranteed to be the same order as either the keys or each function would produce on the same (unmodified) hash.
1
2
for (values %hash) { s/foo/bar/g } # modifies %hash values
for (@hash{keys %hash}) { s/foo/bar/g } # same
Quotealso, solange die reienfolge der keys aufrufe bei jedem aufruf gleich is, wird das funktionieren.
QuoteAber(!) meiner meinung nach is das kein guter style. Will man hier auf nummer sicher gehen, kann man folgendes verwenden:
Quotebut it is guaranteed to be the same order as either the
"keys" or "each" function would produce on the same (unmodified)
hash.
Quotebut it is guaranteed to be the same order as either the
"keys" or "each" function would produce on the same (unmodified)
hash.
QuoteSince Perl 5.8.1 the ordering is different even between different runs of Perl for security reasons (see "Algorithmic Complexity Attacks" in perlsec)
1
2
3
4
5
6
7
8
9
10
11
use strict;
use warnings;
my %hash;
for ( 1 .. 20 ) { $hash{$_}=$_ }
for ( 1 .. 10 ) {
print"values: ";print values %hash;print"\n";
print"keys: ";print keys(%hash);print"\n";
print "\n";
}
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
values: 1171721181613639122014158419105
keys: 1171721181613639122014158419105
values: 1171721181613639122014158419105
keys: 1171721181613639122014158419105
values: 1171721181613639122014158419105
keys: 1171721181613639122014158419105
values: 1171721181613639122014158419105
keys: 1171721181613639122014158419105
values: 1171721181613639122014158419105
keys: 1171721181613639122014158419105
values: 1171721181613639122014158419105
keys: 1171721181613639122014158419105
values: 1171721181613639122014158419105
keys: 1171721181613639122014158419105
values: 1171721181613639122014158419105
keys: 1171721181613639122014158419105
values: 1171721181613639122014158419105
keys: 1171721181613639122014158419105
values: 1171721181613639122014158419105
keys: 1171721181613639122014158419105
|< 1 2 >| | 12 Einträge, 2 Seiten |