stansoad0108 | Bonjour à tous,
J'ai écrit un programme Perl, pour récupérer un lien dans une balise. Cependant dans ma console après exécution de ce programme, on m'affiche :
Code :
- Use of uninitialized value in subroutine entry at Essai_1.pl line 66.
|
Voici mon code :
Code :
- #!/usr/bin/perl
- use strict;
- use warnings;
- use HTML::Parser;
- use LWP::Simple;
- #Variables
- my $baseurl = 'http://www.google.com/';
- my $flag = 0;
- die "usage: $0 site gene\n"
- if @ARGV != 2;
- my $pharmGKB = $ARGV[0];
- my $nom_gene = $ARGV[1];
- #Page URL où parser
- my $url = $baseurl.'search?hl=fr&q='.$pharmGKB.'+'.$nom_gene.'&btnG=Rechercher&meta=';
- #print "$url\n";
- my $PAGE = get($url);
- sub check { defined $_[0] and $_[0] =~ m/$_[1]/ }
- #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 =~ /^a$/
- and check( $attr->{href}, qr{^http://www.pharmgkb.org/do/serve\?objId=} )
- and check( $attr->{class}, qr{^l$} )
- and check( $attr->{onmousedown}, qr{return clk\(this\.href,'','','res','1',''\)} ) ){
- $flag = 1;
- my $URL = $attr->{href};
- print "$URL";
- }
- }
- sub text_rtn {
- my ($text) = @_;
- $text =~ s/\n/ /g;
- if($flag == 1){
- print "$text\n";
- }
- }
- sub end_rtn {
- my ($tag) = @_;
- if ($tag =~ /^\/a$/ && $flag == 1){
- $flag = 0;
- }
- }
- #start parsing
- $parser->parse($PAGE);
-
- #end parser
- $parser->eof;
|
La ligne 66 correspond à $parser -> parse($PAGE)
Merci pour vos commentaires |