• # Dans ce genre là?

    Posté par . En réponse au message inserer une ligne d'un fichier txt dans un autre si le premier mots existe. Évalué à 0.

    #!/usr/bin/perl
    open FILE1,"./fichier1.txt" or die "Cannot open fichier1.txt";
    open FILE2,"./fichier2.txt" or die "Cannot open fichier2.txt";
    open FILE3,">./resultat.txt" or die "Cannot create resultat.txt";
    while (<FILE1>)
    {
     chomp;
     /[^\ ]*$/;
     $common = $&;
     $begin = $`;
     chop $begin;
     $array{$common} = $begin;
    }
    close FILE1;
    while (<FILE2>)
    {
     chomp;
     /^[^\ ]*\ /;
     $common = $&;
     chop $common;
     $end = $';
     print FILE3 "$array{$common} $common $end\n" if exists $array{$common};
    }
    close FILE2;
    close FILE3;

    Attention, ça ne gère pas les doublons.