HI, Anirban.

Regexp and hash of arrays can help you.

my @a =
 
('1900-0','1900-1','NULL','NULL','1900-2','1900-4','1902-5','1902-6','1902-7','1902-8');

my %result;
foreach (@a) {
        next if $_ eq 'NULL';
        my ($earfcn, $pcid) = /^(\d+)-(.+)$/;
        push @{$result{$earfcn}}, $pcid;
}

say "EARFCN=$_,PCID=" . join ("&", @{$result{$_}}) . ";" for sort keys
%result;

Outcome is exatly what you want
EARFCN=1900,PCID=0&1&2&4;
EARFCN=1902,PCID=5&6&7&8;


ср, 6 мая 2015 г. в 10:25, <beginners-digest-h...@perl.org>:

>
> beginners Digest 6 May 2015 07:20:38 -0000 Issue 4811
>
> Topics (messages 125337 through 125337):
>
> Perl array question
>         125337 by: Anirban Adhikary
>
> Administrivia:
>
> To subscribe to the digest, e-mail:
>         <beginners-digest-subscr...@perl.org>
>
> To unsubscribe from the digest, e-mail:
>         <beginners-digest-unsubscr...@perl.org>
>
> To post to the list, e-mail:
>         <beginners@perl.org>
>
>
> ----------------------------------------------------------------------
>
>
>
> ---------- Forwarded message ----------
> From: Anirban Adhikary <anirban.adhik...@gmail.com>
> To: beginners <beginners@perl.org>
> Cc:
> Date: Wed, 6 May 2015 12:49:53 +0530
> Subject: Perl array question
> Hi List
> I have the following array ---
> ('1900-0','1900-1','NULL','NULL','1900-2','1900-4','1902-5','1902-6','1902-7','1902-8');
> There are two part for each element separated by a dash.
> first one known as earfcn and second one is pcid .
> The requirement is  For the same “earfcn”, concatenate the “pcid” values
> using "&" separator between values.
> so the output will be like this
> EARFCN=1900,PCID=0&1&2&4;
> EARFCN=1902,PCID=5&6&7&8;
>
> I am not able to generate any idea how to adress this isuue. Please give
> me some starting point.
>
> Best Regards
> Anirban.
>
>

Reply via email to