Bonjour camarades!

j ai une chaine de caracteres comme ca:
CAN-Mapping:
1000-------- : 0
0010-------- : 0
1010-------- : 1
0011-------- : 0
1011-------- : 1
1110-------- : 2
0110-------- : 2
0111-------- : 2
1111-------- : 2
et j ai ecris ce morceau de code:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
#!/usr/bin/perl -w
 
use strict;
use warnings;
 
 
 
 
print "\n", "CAN-Mapping: ", "\n";
my $can_map = <STDIN>;
chomp $can_map;
print "\n";
 
 
 
my @array=();
my @array_keys=();
my @array_values=();
my @string_to_array=();
my %hash=();
my $signe_de_separation;
 
print my $can_mapings = 'CAN-Mapping:
1000-------- : 0
0010-------- : 0
1010-------- : 1
0011-------- : 0
1011-------- : 1
1110-------- : 2
0110-------- : 2
0111-------- : 2
1111-------- : 2', "\n";
@array=split(/\n/, $can_mapings);
for my $ind1 (@array)
	{
	$ind1 =~ / : \d/;
	$signe_de_separation = $&;
	push(@array_keys, $`);
	push(@array_values, $signe_de_separation);	
	}
		shift(@array_keys);
		shift(@array_values);
 
my $string_to_array=();
 
for (my $i=0; $i<=$#array_keys; ++$i)
{
$hash{$array_keys[$i]}=$array_values[$i];
}
for my $key (keys %hash)
{
foreach my $pos (grep substr($key, $_, 1) =~ /\d/, 0 .. length ($key) - 1)
{
if(substr($can_map, $pos, 4) eq substr($key, $pos,4))
{
print "\n";
print $can_map.$hash{$key};
}
}
}
je donne un input $can_map et je dois lui attribuer une valeur ( : 0, :1 ou :2)
a l aide des valeurs enrigistrer dans $can_mapings.

Exemple:
C:\Perl\bin>perl U:\praktikum\souce_code_perl\test.map.pl

CAN-Mapping:
111100001111

CAN-Mapping:
1000-------- : 0
0010-------- : 0
1010-------- : 1
0011-------- : 0
1011-------- : 1
1110-------- : 2
0110-------- : 2
0111-------- : 2
1111-------- : 2

111100001111 : 2
alors les bits "fixes" de mon inputs sont identiques avec les bits fixes de
1111-------- : 2 alors on attribue a 111100001111 la valeur ' : 2'

si l ordre des can_mapings change je sais pas quoi faire
exemple:
CAN-Mapping:
1000-------1 : 0
0010---11--- : 0
1010-------- : 1
0011-----1-- : 0
1011-------- : 1
1110----11-- : 1
0110-------- : 2
0111-------- : 2
1----------1 : 2
dans ce cas ce que j ai ecris dans mon code:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
if(substr($can_map, $pos, 4) eq substr($key, $pos,4))
{
print "\n";
print $can_map.$hash{$key};
}
n est plus valable et je dois chercher une autre methode!
c est mon probleme!
Merci pour votre aide!