Thread An key bei values Schleife (34 answers)
Opened by bianca at 2010-04-14 12:07

bianca
 2010-04-14 12:25
#135970 #135970
User since
2009-09-13
7016 Artikel
BenutzerIn

user image
Überschlagt Euch doch nicht gleich.

Ich möchte im grep{} ein split machen und das split-Ergebnis wiederum ist key in einem anderen Hash. Um nicht schon "Use of uninitialized value" bei Verwendung des Split-Ergebnisses zu bekommen will ich das vorher abfragen.

Hier der Code:
Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/usr/bin/perl -w
use strict;
use warnings;
my %user = (
        1 => 'hallo|hallo|hallo|hallo|hallo',
        2 => 'hallo|hallo|hallo',
);
my %foo = (
        1 => 'hallo',
);
foreach my $user (
        grep {
                (split /\|/,$user{$_})[4] # das matcht auf garnichts
                #defined (split /\|/,$user{$_})[4] schmeisst Syntax und Implicit-Error
                        &&
                defined $foo{(split /\|/,$user{$_})[4]}
        }
        keys %user
) {
        print "Treffer: $user\n";
}


Edit: Daher hatte ich mit values versucht aber das ist bestimmt Bullshit.
Last edited: 2010-04-14 12:26:23 +0200 (CEST)
10 print "Hallo"
20 goto 10

View full thread An key bei values Schleife