Bonjour à tous,
Je poste mon problème ici, car je ne vois pas du tout où est mon erreur !!
Il m'affiche bien les premières instructions, cependant il parse pas le fichier $filename et me ressort pas les informations souhaitées.
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115 #!/usr/bin/perl use warnings; use HTML::Form; use LWP::Simple; use HTML::Parser(); use HTML::LinkExtor; #Constants my $baseUrl = 'http://www.pharmgkb.org/do/serve?objId='; #Variables : my $flag = 0; my $URL; my $Role; my $Code; my $PharmPage = ''; ($#ARGV == 1) or die $!; $Role = $ARGV[0]; $Code = $ARGV[1]; print "$Code\n"; print "$Role\n"; if ($Role eq 'Gene'){ print "$Code + Gene\n"; #Vérifie $Code my $URL = $baseUrl.$Code."&objCls=$Role"; print "$URL\n"; #Vérifie $URL my $PharmPage = get("$URL"); #print "$PharmPage\n"; #Print le code Source entierement (vérification) } elsif ($Role eq 'Drug') { print "$Code + Drug\n"; my $URL = $baseUrl.$Code."&objCls=$Role"; print "$URL\n"; my $PharmPage = get("$URL"); } elsif ($Role eq 'Disease') { print "$Code + Disease\n"; my $URL = $baseUrl.$Code."&objCls=$Role"; print "$URL\n"; my $PharmPage = get("$URL"); } else {(exit); } #****************************************** my $filename = get("$PharmPage"); #Parser my $parser = HTML::Parser->new(start_h => [\&start_rtn,"tag, attr"], text_h => [\&text_rtn, "text"], end_h => [\&end_rtn, "tag"]); sub start_rtn { my ($tag, $attr) = @_; if ($tag =~ /^title$/){ $flag = 1; } if ($tag =~ /^a$/ and defined $attr->{href} and $attr->{href} =~ /^\/do\/serve\?objId=PA[0-9]+&objCls=Gene$/){ $flag = 2; } if ($tag =~ /^a$/ and defined $attr->{href} and $attr->{href} =~ /^\/do\/serve\?objId=PA[0-9]+&objCls=Disease$/){ $flag = 3; } if ($tag =~ /^a$/ and defined $attr->{href} and $attr->{href} =~ /^\/do\/serve\?objId=PA[0-9]+&objCls=Drug$/){ $flag = 4; } } sub text_rtn { my ($text) = @_; $text =~ s/\n//g; if($flag == 1){ print "Le titre : $text \n"; } if($flag == 2){ print "Genes relatifs : $text \n"; } if($flag == 3){ print "Maladies relatives : $text \n"; } if($flag == 4){ print "Médicaments relatifs : $text \n"; } } sub end_rtn { my ($tag) = @_; if ($tag =~ /^\/title$/){ $flag = 0; } if ($tag =~ /^\/a$/ && ($flag==2 ||$flag==3 || $flag==4)){ $flag = 0; } } #start parsing $parser->parse($filename); #end parser $parser ->eof;
Je tape dans ma console le nom de mon programme, avec comme argument
$Role et $Code (mis dans le tableau @ARGV), Si il reconnait des noms de roles et de codes précis, Ces 2 variables sont ajouter dans l'adresse URL, et je sort une adresse URL final $PharmPage, que je veux parser...
RIEN NE N'AFFICHE !!!
De plus on m'indique en erreur :
La ligne 149 correspond dans mon programme a la ligne :
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 PA50 Gene PA50 + Gene http://www.pharmgkb.org/do/serve?objId=PA50&objCls=Gene Use of uninitialized value in subroutine entry at Essai_2.pl line 149 (#1) (W uninitialized) An undefined value was used as if it were already defined. It was interpreted as a "" or a 0, but maybe it was a mistake. To suppress this warning assign a defined value to your variables. To help you figure out what was undefined, perl tells you what operation you used the undefined value in. Note, however, that perl optimizes your program and the operation displayed in the warning may not necessarily appear literally in your program. For example, "that $foo" is usually optimized into "that " . $foo, and the warning will refer to the concatenation (.) operator, even though there is no . in your program.Merci pour vos réactions
Code : Sélectionner tout - Visualiser dans une fenêtre à part $parser->parse($filename);




Répondre avec citation



Partager