Hello leoberbert,

As the monks already stated, we do not know exactly what you are trying to do. It would help us a lot to help you coming up with a solution to your problem if you provided us some steps/description etc.

Well I put together a simple script on how I would approach your problem, but I am not sure about the calculation that you are doing with the numbers so I left them unchanged. I am sure that you can make the calculation your self and update the code.

#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my $path_to_file = 'test.txt'; open my $fh, '<', $path_to_file or die "Could not open " . $path_to_file . " $!\n"; chomp(my @lines = <$fh>); close $fh or die "Could not close " . $path_to_file . " $!\n"; # Remove empty lines if this is desired? @lines = grep /\S/, @lines; my %HoA; foreach my $line (@lines) { my ($match, $remaining) = split(/\|\|\|/, $line); push (@{$HoA{$match}}, $remaining); } print Dumper \%HoA; my @updated_lines; foreach my $key (keys %HoA) { my $concat_str; foreach my $i ( 0 .. $#{ $HoA{$key} } ) { if ($i == 0){ $concat_str .= $HoA{$key}[$i] . "; "; } $concat_str .= $HoA{$key}[$i] . " "; } # Trim white space on right $concat_str =~ s/\s+$//; push @updated_lines, $key.$concat_str.'|||'; } print Dumper \@updated_lines; __END__ $ perl test.pl $VAR1 = { '21997' => [ '70049,,20170428154818,20170527235959', '70070,,20170428154739,20170527235959' ], '21998' => [ '70049,,20170428154818,20170527235959', '70070,,20170428154739,20170527235959', '70071,,20170428154739,20170527235959' ] }; $VAR1 = [ '2199770049,,20170428154818,20170527235959; 70049,,201704281 +54818,20170527235959 70070,,20170428154739,20170527235959|||', '2199870049,,20170428154818,20170527235959; 70049,,201704281 +54818,20170527235959 70070,,20170428154739,20170527235959 70071,,2017 +0428154739,20170527235959|||' ];

Update: Sorry because of rush I did not resolve correctly the output. See new code bellow:

#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my $path_to_file = 'test.txt'; open my $fh, '<', $path_to_file or die "Could not open " . $path_to_file . " $!\n"; chomp(my @lines = <$fh>); close $fh or die "Could not close " . $path_to_file . " $!\n"; # Remove empty lines if this is desired? @lines = grep /\S/, @lines; my %HoA; foreach my $line (@lines) { my ($match, $remaining) = split(/\|\|\|/, $line); push (@{$HoA{$match}}, $remaining); } print Dumper \%HoA; my @updated_lines; foreach my $key (keys %HoA) { my $concat_str; foreach my $i ( 0 .. $#{ $HoA{$key} } ) { if ($i == 0){ $concat_str .= $HoA{$key}[$i] . "; "; } else { $concat_str .= $HoA{$key}[$i] . " "; } } # Trim white space on right $concat_str =~ s/\s+$//; my $final_str = join ('', $key,'|||' , $concat_str, '|||'); push @updated_lines, $final; } print Dumper \@updated_lines; __END__ $ perl test.pl $VAR1 = { '21997' => [ '70049,,20170428154818,20170527235959', '70070,,20170428154739,20170527235959' ], '21998' => [ '70049,,20170428154818,20170527235959', '70070,,20170428154739,20170527235959', '70071,,20170428154739,20170527235959' ] }; $VAR1 = [ '21997|||70049,,20170428154818,20170527235959; 70070,,201704 +28154739,20170527235959|||', '21998|||70049,,20170428154818,20170527235959; 70070,,201704 +28154739,20170527235959 70071,,20170428154739,20170527235959|||' ];

Hope this helps.

Seeking for Perl wisdom...on the process of learning...not there...yet!

In reply to Re: Doubts group data by thanos1983
in thread Doubts group data by leoberbert

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.