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
| #!/usr/bin/perl
system $^O eq 'MSWin32' ? 'cls' : 'clear';
# Declare the subroutines
sub trim($);
# Perl trim function to remove whitespace from the start and end of the string
sub trim($)
{
my $string = shift;
$string =~ s/^\s+//;
$string =~ s/\s+$//;
return $string;
}
open(FILE,$ARGV[0]) || die ("Impossible d'ouvrir le fichier $ARGV[0]");
open(TAR,">res_pl.txt");
while(<FILE>)
{
if ( $_ =~ /^00.*/ )
{
(my $distributeur = $_) =~ s/^00(\d{7})(.*)/$1/;
printf "Distributeur : $distributeur";
}
elsif ( $_ =~ /^99.*/ )
{
($distributeur = $_) =~ s/^00(\d{7})(.*)/$1/;
}
else
{
(my $natcompt = $_) =~ s/^(.{18})(.{10})(.*)$/$2/;
(my $centcout = $_) =~ s/^(.{28})(.{10})(.*)$/$2/;
(my $montant = $_) =~ s/^(.{38})(.{11})(.*)$/$2/;
(my $signe = $_) =~ s/^(.{49})(.{1})(.*)$/$2/;
(my $axe1 = $_) =~ s/^(.{50})(.{7})(.*)$/$2/;
(my $axe2 = $_) =~ s/^(.{57})(.{18})(.*)$/$2/;
$natcompt = trim($natcompt);
$centcout = trim($centcout);
printf "Nature comptable : %s, Centre de coût : %s, Montant : %d, Signe : %s, Axe 1 : %s, Axe 2 : %s\n", $natcompt, $centcout, $montant, $signe, $axe1, $axe2;
}
}
close(TAR);
close(FILE); |
Partager