Thread Auf Hash Werte zugreifen! (5 answers)
Opened by Lauvia at 2015-07-28 15:09

Lauvia
 2015-07-29 15:54
#181685 #181685
User since
2013-09-05
42 Artikel
BenutzerIn
[default_avatar]
OK ich habe was anderes ausprobiert!

Code (perl): (dl )
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
59
60
61
62
63
64
65
66
67
68
my 
%Signal_ref = (
   10.005108 => {
        PSIP1 => "-0.039999999999992",
        SBC_SC_A1_AR2 => {
               DATA => "22 0D 00 00 20 80 F8 7F  ",
               DLC => "8"
              }
   },
   10.015101 => {
        PSIP1 => "-0.330000000000013",
        SBC_SC_A1_AR2 => {
                 DATA => "D2 0E 00 00 27 80 BE 7F  ",
                 DLC => "8"
                 }
   },
   10.025102 => {
        PSIP1 => "-0.169999999999987",
        SBC_SC_A1_AR2 => {
                 DATA => "88 0F 00 00 20 80 DE 7F  ",
                 DLC => "8"
                 }
   },
   10.034626 => {
        PSIP1 => "-0.490000000000009",
        SBC_SC_A1_AR2 => {
                 DATA => "CB 00 00 00 00 80 9E 7F  ",
                 DLC => "8"
                 }
   },
   10.045139 => {
        PSIP1 => "-0.27000000000001",
        SBC_SC_A1_AR2 => {
                 DATA => "47 01 00 00 17 80 CA 7F  ",
                 DLC => "8"
                 }
   },
   10.055142 => {
        PSIP1 => "-0.449999999999989",
        SBC_SC_A1_AR2 => {
                 DATA => "11 02 00 00 F1 7F A6 7F  ",
                 DLC => "8"
                 }
   },
   10.065121 => {
        PSIP1 => "-0.129999999999995",
        SBC_SC_A1_AR2 => {
                 DATA => "FD 03 00 00 12 80 E6 7F  ",
                 DLC => "8"
                }
   },
        
);

my $i = 1;
for my $time(sort {$a<=>$b} keys %Signal_ref)
{
        print"Stimestamp_"."$i : $time\n";
        
        $i++;
        for my $msg(sort keys %{$Signal_ref{$time}})
        {
                print"my signal: $msg\n";
                #print"$Signal_ref{$time}\n";
        }
        
        print "\n";
}


Das ist OK, ich ich bekomme was ich möchte (einfach kopieren und laufen lassen; aber der Hash oben ist anders als der den ich von der Simulation habe (siehe unten, single quote und 2 geschweiften Klammern am Anfang und Ende)

Code (perl): (dl )
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
Signal_ref = {
  '10.005108' => {
    'PSIP1' => '-0.039999999999992',
    'SBC_SC_A1_AR2' => {
      'DATA' => '22 0D 00 00 20 80 F8 7F  ',
      'DLC' => '8'
    }
  },
  '10.015101' => {
    'PSIP1' => '-0.330000000000013',
    'SBC_SC_A1_AR2' => {
      'DATA' => 'D2 0E 00 00 27 80 BE 7F  ',
      'DLC' => '8'
    }
  },
  '10.025102' => {
    'PSIP1' => '-0.169999999999987',
    'SBC_SC_A1_AR2' => {
      'DATA' => '88 0F 00 00 20 80 DE 7F  ',
      'DLC' => '8'
    }
  },
  '10.034626' => {
    'PSIP1' => '-0.490000000000009',
    'SBC_SC_A1_AR2' => {
      'DATA' => 'CB 00 00 00 00 80 9E 7F  ',
      'DLC' => '8'
    }
  },
  '10.045139' => {
    'PSIP1' => '-0.27000000000001',
    'SBC_SC_A1_AR2' => {
      'DATA' => '47 01 00 00 17 80 CA 7F  ',
      'DLC' => '8'
    }
  },
  '10.055142' => {
    'PSIP1' => '-0.449999999999989',
    'SBC_SC_A1_AR2' => {
      'DATA' => '11 02 00 00 F1 7F A6 7F  ',
      'DLC' => '8'
    }
  },
};


Damit der Stückcode:

Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
my $i = 1;
for my $time(sort {$a<=>$b} keys %$Signal_ref)
{
        print"Stimestamp_"."$i : $time\n";
        
        $i++;
        for my $msg(sort keys %{$Signal_ref{$time}})
        {
                print"my signal: $msg\n";
                #print"$Signal_ref{$time}\n";
        }
        
        print "\n";
}


Und da geht es nicht mehr.

Wo ist der wesentliche Unterschied zwischen beiden Hash. Worauf muss ich bei dereferenzieren achten!?

View full thread Auf Hash Werte zugreifen!