Use of uninitialized value in concatenation (.) or string
Bonjour,
Le script qui fonctionne mais il a un message d'erreur :
Use of uninitialized value in concatenation (.) or string at xxxl line 57, <> line 1.
Use of uninitialized value in addition (+) at xxx line 70, <> line 7.
voiçi ma ligne 57
print "M: $hash{$id}{'M'}\tI: $hash{$id}{'I'}\tH: $hash{$id}{'H'}\tD: $hash{$id}{'D'}\n";#verif
et ligne 70
$hash{$_}{'indel'} = $hash{$_}{'I'} + $hash{$_}{'D'};
Je comprend que c'est parce que mes variables sont vides, mais j'ai bien fait le test si ma variable est définie
Code:
1 2 3
| if ( $res[$i+1] ) {# vrai si $res[$i+1] est indéfini ou si $res[$i+1] est faux
...
} |
je fais référence un post antérieur
par exemple pour b 1H98M2H, j'ai pas de valeur pour I et D
M: 98 I: H: 3 D:
-DATA-
b 1H98M2H
c 1H100M
d 63M5D37M1H
f 1H68M3D31M1H
g 1H75M1I24M
h 1H38M1I60M1H
Code:
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
| #!/usr/bin/perl
use strict;
use warnings;
my %hash;
my $id;
while( my $ligne = <> ) {
chomp $ligne;
if($ligne =~ /(.+)\t(.+)$/){
$id=$1;
my $mots=$2;
$hash{$id}{'code_mots'} = $mots;
my @res = $hash{$id}{'code_mots'} =~ /(\d+)([a-z]+)/gi;
my %comptage;
my $nb_M;
my $nb_I;
my $nb_H;
my $nb_D;
for ( my $i = 0; $i < scalar(@res) -1; $i = $i +2 ) {
if ( $res[$i+1] ) {
$comptage{$res[$i+1]} += $res[$i];
if( $res[$i+1] eq "M"){
$hash{$id}{'M'} = $comptage{$res[$i+1]};
$nb_M += $comptage{$res[$i+1]};
}
if( $res[$i+1] eq "I"){
$hash{$id}{'I'} = $comptage{$res[$i+1]} ;
$nb_I += $comptage{$res[$i+1]};
}
if( $res[$i+1] eq "H"){
$hash{$id}{'H'} = $comptage{$res[$i+1]} ;
$nb_H += $comptage{$res[$i+1]};
}
if( $res[$i+1] eq "D"){
$hash{$id}{'D'} = $comptage{$res[$i+1]} ;
$nb_D += $comptage{$res[$i+1]};
}
}
}
print "M: $hash{$id}{'M'}\tI: $hash{$id}{'I'}\tH: $hash{$id}{'H'}\tD: $hash{$id}{'D'}\n";
}
}
foreach ( sort keys %hash ) {
$hash{$_}{'del'} = $hash{$_}{'I'} + $hash{$_}{'D'};
} |