Dear Monks, could you give me a hand ?

I would like to gather some elements of a list into one element.

My start file looks like
0601 3 NORM 2 ALLO XLF753 U 0045 0050 0603 5 NORM 2 ALLO ADR2CG 0430 0438 0604 6 NORM 2 ALLO AF681VC i U 0500 0510 0605 7 NORM 2 ALLO AF651PQ i 0515 0523 0606 8 NORM 2 ALLO AF713BR i 0445 0453 0607 9 NORM 2 ALLO AFR100M i 0520 0533 0609 11 NORM 2 ALLO GJT775 i E 2300 2315 0610 12 NORM 2 ALLO AF661WN i 0450 0500

I would like that my outfile looks like :
0601;3;NORM;2;ALLO;XLF753;U;0045;0050; 0603;5;NORM;2;ALLO;ADR2CG;;0430;0438; 0604;6;NORM;2;ALLO;AF681VC;i U;0500;0510; 0605;7;NORM;2;ALLO;AF651PQ;i;0515;0523; 0606;8;NORM;2;ALLO;AF713BR;i;0445;0453; 0607;9;NORM;2;ALLO;AFR100M;i;0520;0533; 0609;11;NORM;2;ALLO;GJT775;i E;2300;2315; 0610;12;NORM;2;ALLO;AF661WN;i;0450;0500;

So I have made a split and I took into consideration several cases, depending on the configuration of the lines (if they have no single letter, one single letter or several)
I have made a code but that does not seem to work. Could you please tell me where I was wrong ? Thanks
#!/usr/bin/perl use strict; use warnings; # this is the file we wish to have in a good format my $file = "$ARGV[0]"; my $Current_Dir = `pwd`; # print STDOUT "the current directory is $Current_Dir"; open(INFILE,"$ARGV[0]") or die "Can't open $ARGV[0]: $!"; # name of the OUTFILE # do not forget the "" if # never put a \n at the end of the OUTFILE name otherwise it does not +create the output my ${outfile_name} = "bon_format_$file"; # to open the file # OUTFILE is the name of the HANDLE in this case open (OUTFILE, ">${outfile_name}.csv") or die "Can't open ${outfile_ +name}.csv: $!"; my @Parts; my $part; while (<INFILE>) { # the lines are composed of elements separated by a point comma my $Line = $_; my @Elements = split(";", $Line); my $element = $Elements[1]; @Parts = split(" ",$element); print STDOUT "le septième élément est $Parts[6]\n"; my $longueur = @Parts; print STDOUT "le nombre d'éléments est $longueur\n"; # case where $Parts[5] is ADR2G and $Parts[6] is 2045 if (($Parts[5] eq /\w+\d+/) & ($Parts[6] eq /\d\d\d\d/)){ print OUTFILE "$Parts[5];$Parts[6]\n"; } # case where $Parts[6] is E and $Parts[7] is 6043 if (($Parts[6] eq /\w/) & ($Parts[7] eq /\d\d\d\d/)){ print OUTFILE "$Parts[6];$Parts[7]\n"; } # case where $Parts[6] is i, $Parts[7] is E and $Parts[8] +is 6043 if (($Parts[6] eq /\w/) & ($Parts[7] eq /\w/) & ($Parts[8] + eq /\d\d\d\d/)){ print OUTFILE "$Parts[6] $Parts[7];$Parts[8]\n"; } # case where $Parts[6] is E, $Parts[7] is i, $Parts[8] is +U and $Parts[8] is 3065 if (($Parts[6] eq /\w/) & ($Parts[7] eq /\w/) & ($Parts[8] + eq /\w/) & ($Parts[9] eq /\d\d\d\d/)){ print OUTFILE "$Parts[6] $Parts[7] $Parts[8];$Parts[9]\n"; } } close INFILE; close OUTFILE;

In reply to gathering of some elements of a list by steph_bow

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.