Hi Илья,

some comments on your code:

On Wed, 06 May 2015 08:09:01 +0000
Илья Рассадин <elcaml...@gmail.com> wrote:

> 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');
>

Always start with "use strict;" and "use warnings;" or equivalent:

http://perl-begin.org/tutorials/bad-elements/#no-strict-and-warnings
 
> my %result;
> foreach (@a) {

It's not a good idea to use $_ as a loop variable because it can get
clobberred/devastated too easily. Better use a "my" lexical variable to iterate:

http://perl-begin.org/tutorials/bad-elements/#overuse_dollar_underscore

>         next if $_ eq 'NULL';

next should use an explicit loop label:

http://perl-begin.org/tutorials/bad-elements/#flow-stmts-without-labels

>         my ($earfcn, $pcid) = /^(\d+)-(.+)$/;

1. Always check that the regex match was succesful:

http://perl-begin.org/tutorials/bad-elements/#regexes_wo_check_for_match_success

2. \d will also match Unicode digits . Better write it as [0-9].

3. You may wish to be more specific than ".+".

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

Again, an implicit loop using $_.

Regards,

        Shlomi Fish

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

-- 
-----------------------------------------------------------------
Shlomi Fish       http://www.shlomifish.org/
http://www.shlomifish.org/humour/Summerschool-at-the-NSA/

Mastering ‘cat’ is almost as difficult as herding cats.
    — http://www.shlomifish.org/humour/bits/Mastering-Cat/

Please reply to list if it's a mailing list post - http://shlom.in/reply .

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to