Leser: 26
my $wanted_hash=pick("hash where field='value' in", \@array);
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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
#!/usr/bin/perl use strict; use warnings; use Data::Dumper; package LispTree; use Moose; # with 'RoleDigraph'; use overload '""' => \&to_s; has 'op' => ( is => 'ro' ); has 'l' => ( is => 'rw' ); has 'r' => ( is => 'rw' ); my $operations = { '*' => sub { $_[0] * $_[1] }, '+' => sub { $_[0] + $_[1] }, '/' => sub { $_[0] / $_[1] }, '-' => sub { $_[0] - $_[1] }, }; sub to_s { my $self = shift; my $o = '(' . $self->op . ' '; $o .= blessed $self->l ? $self->{l}->to_s : $self->l; $o .= ' '; $o .= blessed $self->r ? $self->{r}->to_s : $self->r; $o .= ')'; return $o; } sub to_rpn { my $self = shift; my $o = blessed $self->l ? $self->{l}->to_rpn : $self->l; $o .= ' '; $o .= blessed $self->r ? $self->{r}->to_rpn : $self->r; $o .= ' ' . $self->op; return $o; } sub calc { my $self = shift; my $l = blessed $self->l ? $self->{l}->calc : $self->l; my $r = blessed $self->r ? $self->{r}->calc : $self->r; return $operations->{$self->op}->( $l, $r ); } package main; my $root = LispTree->new( op => '+' ); $root->l(LispTree->new( op => '+', l => 6, r => 6 )); my $leaf = LispTree->new( op => '*', l => 15, r => 2 ); $root->r($leaf); print $root . "\n" x 2 . $root->to_rpn . "\n" . $root->calc . "\n";
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
@tables=(
{
"table" => "table1",
"description" => "bla",
"datafield" => [
{
name="field1",
assoc_table="table2",
}
]
},
{
"table" => "table2",
"description" => "blubb",
"datafield" => [
{
name="field1",
assoc_table="table3",
}
]
},
);
2009-06-28T10:29:14 xubasoWenn ich z.B. bei "table1" das datafield "field1" bearbeite, steht dort als assoziierte Tablelle table2. Jetzt möchte ich möglichst ohne viel tippen zu müssen (und wenn möglich lesbar) ad-hoc auf die Tabelle "table2" zugreifen.
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 33
#!/usr/bin/perl use strict; use warnings; use Data::Dumper; use Carp; my @tables = ( { "table" => "table1", "description" => "bla", "datafield" => [ { name => "field1", assoc_table => "table2", } ] }, { "table" => "table2", "description" => "blubb", "datafield" => [ { name => "field1", assoc_table => "table3", } ] }, ); my %lut = map { $_->{'table'} => $_->{'datafield'} } @tables; print Dumper \%lut;
2009-06-28T10:29:14 xubasoHallo & Danke für die Antworten,
@LanX-
Ich habe mir grep mal angesehen und es kommt dem schon nahe, aber "nur" für einfache Listen, nicht für verschachtelte.