IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Langage Perl Discussion :

pbm avec whil perl


Sujet :

Langage Perl

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éclairé
    Profil pro
    Inscrit en
    Décembre 2006
    Messages
    296
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2006
    Messages : 296
    Par défaut pbm avec whil perl
    bonjour à tous,
    j'ai un pbm avec un script perl que j'ai beau essayé de résoudre sans résultats.
    avec mon programme je parse des fichiers .txt pour récupérer des infos et les envoyées à la base de données.
    voila l'exemple d'un fichier
    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
     
    ====VE01
    GLRIL:ED=OUI;
     
       CMD GLRIL  00004   07-07-13 07-06-14
       INP GLRIL  00004   07-07-13 07-06-14
     
     
     
       RES GLRIL  00004   07-07-13 07-06-14
        CEN=1/07-07-13/07 H 06 MN 14/LISTAGE DE L'ETAT DES GLR
        TRAITEMENT TJGLR0 ACC
        AFGRX=001-00 GLRX=0000 BRCX=A ETAT=ES    BRCX=B ETAT=ES    TR=GLR     
        AFGRX=001-01 GLRX=0001 BRCX=A ETAT=ES    BRCX=B ETAT=ES    TR=GLR     
        AFGRX=001-02 GLRX=0002 BRCX=A ETAT=ES    BRCX=B ETAT=ES    TR=GLR     
        AFGRX=001-03 GLRX=0003 BRCX=A ETAT=ES    BRCX=B ETAT=ES    TR=GLR     
        AFGRX=001-04 GLRX=0004 BRCX=A ETAT=ES    BRCX=B ETAT=ES    TR=GLR     
        AFGRX=001-05 GLRX=0005 BRCX=A ETAT=ES    BRCX=B ETAT=ES    TR=GLR     
        AFGRX=001-06 GLRX=0006 BRCX=A ETAT=ES    BRCX=B ETAT=ES    TR=GLR     
        AFGRX=001-07 GLRX=0007 BRCX=A ETAT=ES    BRCX=B ETAT=ES    TR=GLR     
        AFGRX=001-08 GLRX=0008 BRCX=A ETAT=ES    BRCX=B ETAT=ES    TR=LAH     
        AFGRX=022-15 GLRX=0351 BRCX=A ETAT=BLOS                    TR=LAH
        AFGRX=022-16 GLRX=0391 BRCX=A ETAT=BLOS                    TR=LAH
        AFGRX=022-19 GLRX=0361 BRCX=A ETAT=BLOS                    TR=GLR
             NBEQ = 1172
             NBEQPT = 1172
        TRAITEMENT TJGLR0 EXC
     
    COMMANDE EXECUTEE
     
       RPT GLRIL  00004   07-07-13 07-06-14
           EXC
    avec mon code perl j'arrive à récupérer seulement la première ligne.
    le voila amon 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
    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
     
    use strict;
    use warnings;
    use DBI;
     
    my $pDirectory;
    my $path =  "C:/Program Files/EasyPHP1-8/www/traitement/sources";
     
     
    opendir ($pDirectory,$path)
    or die ("Directory ".$path." can't be open!\n");
     
    my @Directory_list = readdir($pDirectory);	
    closedir ($pDirectory);
     
    foreach my $File (@Directory_list)
    {
        if( $File =~ m/\.txt$/ )
        {
            #.....VOILA MON CODE POUR TRAITER TOUS LES FICHIERS DE LA LISTE.............................
    open my ($src), '<', "$path/$File" or die "E/S : $!\n";
    		# Connect to the database.
    		my $dbh = DBI->connect( "DBI:mysql:database=tdm;host=localhost",
    	    "chakri", "farid", { 'RaiseError' => 1 } );
     
    my $sth =
      $dbh->prepare(
            "INSERT INTO glril (date, heure, ct,nbeq, nbeqpt, date_intr, afgrx, glrx, brcx, etat, tr, brcxb, etatb)"
          . " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" );
     
     
    # variable d'état pour savoir si l'on se trouve dans ule paragraphe qu'on veut imprimer ($in == 2), après une commande ($in == 1),
    # ou en dehors de tout cela ($in == 0)
    my $in = 0; 
    my ($date, $heure, $ct,$nbeq, $nbeqpt,$afgrx, $glrx, $brcx, $etat, $tr, $brcxb, $etatb);
    my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
    my $dateUs =  (1900+$year)."-".($mon+1)."-".$mday;
    while (<$src>) {
    			if ( not $in and m/^====([\w\d]+)/ ) {
    				$ct = $1;
    			}
    			elsif ( not $in and my ($cmd) = (m/\s*GLRIL/) ) {
    				$in = 1;
    			}
    			elsif ($in == 1
    			and m{^\s+CEN=([\w\d]+)/(\d{2}\-\d{2}\-\d{2})/(\d{2})\s+\w{1}\s+(\d{2})\s+\w{2}\s+(\d{2})/(.*)}x 
    			)
    			{
    				$date = $2;
    				$heure = $3.':'.$4.':'.$5;
    			}
     
    			elsif ( $in == 1 and m/^\s*TRAITEMENT ...... ACC/ ) {
    				$in = 2;	
    			}
    			elsif (
    			$in == 2
    				and m{^\s+AFGRX=(\d{3}\-\d{2})\s+GLRX=([\w\d]+)\s+BRCX=([\w\d]+)\s+ETAT=([\w\d]+)\s+BRCX=([\w\d]+)\s+ETAT=([\w\d]+)\s+TR=([\w\d]+)}x
     
    			)
    			{
    				$afgrx = $1;
    				$glrx = $2;
    				$brcx = $3;
    				$etat = $4;
    				$brcxb = $5;
    				$etatb = $6;
    				$tr = $7;
    			}
    			elsif (
    			$in == 2
    				and m{^\s+AFGRX=(\d{3}\-\d{2})\s+GLRX=([\w\d]+)\s+BRCX=([\w\d]+)\s+ETAT=([\w\d]+)\s+TR=([\w\d]+)}x 	
    			)
    			{
    				$afgrx = $1;
    				$glrx = $2;
    				$brcx = $3;
    				$etat = $4;
    				$tr = $5;
    			}
    			elsif ( $in == 2
    				and m{^\s+NBEQ\s+=\s+([\w\d]+)}x
    			)
    			{
    				$nbeq = $1;
    			}
    			elsif (
    				$in == 2
    				and m{^\s+NBEQPT\s+=\s+([\w\d]+)}x
    			)
    			{
    				$nbeqpt = $1;
    					if ( defined $nbeq ) {
    					$sth->execute($date, $heure, $ct, $nbeq, $nbeqpt, $dateUs, $afgrx, $glrx, $brcx, $etat, $tr, $brcxb, $etatb)
    					or die "pb de requete : $DBI::errstr";
    					}
    					($date, $heure, $nbeq, $nbeqpt, $afgrx, $glrx, $brcx, $etat, $tr, $brcxb, $etatb) = (undef) x 10;
    			}	
    			elsif ( $in == 2 and m/^\s*TRAITEMENT ...... EXC/ ) {
    				$in = 1;
    			}
    			elsif ( $in == 1 and m/^\s*EXC\s*$/ ) {
    	        $in = 0;
    			}
    }
    close $src;
    $dbh->disconnect;
            #.....VOILA LA FIN DE MON CODE POUR TRAITER TOUS LES FICHIERS DE LA LISTE.............................
        }
    }
    la question est : comment faire pour récupérer toutes les lignes.

  2. #2
    Membre confirmé Avatar de pymouse
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Décembre 2004
    Messages
    137
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Décembre 2004
    Messages : 137
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    open(FICHIER,"fichier.txt") or die("open");
     
    while($ligne = <FICHIER>)
    {
    #traitement ligne par ligne
    }

  3. #3
    Membre éclairé
    Profil pro
    Inscrit en
    Décembre 2006
    Messages
    296
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2006
    Messages : 296
    Par défaut
    je m'excuse je n'avais pas met le bon script
    j'ai rectifier regardez en haut
    merci de m'aidez

  4. #4
    Membre éclairé
    Profil pro
    Inscrit en
    Décembre 2006
    Messages
    296
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2006
    Messages : 296
    Par défaut
    c bon j'ai résoulu mon pbm

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. probleme avec script perl grab_tv_fr.pl
    Par ZiMo dans le forum Langage
    Réponses: 6
    Dernier message: 30/11/2005, 17h12
  2. pbm avec setMinimumSize()
    Par toxyshow dans le forum Agents de placement/Fenêtres
    Réponses: 2
    Dernier message: 26/11/2005, 18h30
  3. pbm avec les foreigns keys.....
    Par j_bonc dans le forum PostgreSQL
    Réponses: 4
    Dernier message: 11/06/2004, 10h23
  4. [langage] Pb avec Active perl :s
    Par Cetras dans le forum Langage
    Réponses: 2
    Dernier message: 02/09/2003, 13h28
  5. Pbm avec les '&'...
    Par AmaX dans le forum Composants VCL
    Réponses: 2
    Dernier message: 19/08/2002, 11h08

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo