Richard Lee wrote:
below sub works fine except the line where key is default.
Instead of printing out PCMU only once, it's printing it out 40 times randomly..
Trying to figure out what I did wrong.

Please leave me a feedback.

thank you.

156  time(s) Codec(s)  : unassigned_38
185 time(s) Codec(s) : G729 1966 time(s) Codec(s) : PCMU PCMU PCMU PCMU PCMU PCMU PCMU PCMU PCMU PCMU PCMU PCMU PCMU PCMU PCMU PCMU PCMU PCMU PCMU PCMU PCMU PCMU PCMU PCMU PCMU PCMU PCMU PCMU PCMU PCMU PCMU PCMU PCMU PCMU PCMU PCMU PCMU PCMU PCMU PCMU

sub codec_list {
#my @codec_d = qw/0 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--71 72--76 77--95 96--127/;
my @codec_d = qw/0 default 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 A B C D/;
my @codec_i = qw/PCMU PCMU Reserved Reserved GSM G723 DVI4 DVI4 LPC PCMA G722 L16 L16 QCELP CN MAP G728 DVI4 DVI4 G729 reserved unassigned unassigned unassigned unassigned unassigned CelB JPEG unassigned nv unassigned unassigned H261 MPV MP2T H263
                      unassigned reserved unassigned dynamic/;
     my %codec_r;
     my @return_codec;
     @[EMAIL PROTECTED] = (@codec_i);
     my $number = shift;
     HS: for ( @$number ) {
           my $request_key = $_;
           #next unless $request_key =~ /^\d+$/;
           for my $o ( keys  %codec_r ) {
if ( $request_key eq $o ) { push @return_codec, $codec_r{$o};
              } elsif ( $request_key eq 'default' ) {

Your problem is that neither $request_key nor 'default' changes in the inner loop so $codec_r{'default'} is added for every element of @codec_d. You probably want to put "next HS;" after the push().


push @return_codec, $codec_r{'default'}; <--- problem line
              } elsif ( ($o =~ /A|B|C|D/ ) ) {
if ( ( $request_key >= 35 ) and ( $request_key <= 71 )) { push @return_codec, join ('_' , $codec_r{'A'}, $request_key );
                         next HS;
} elsif ( ( $request_key >= '72' ) and ( $request_key <= '76' )) {

Why are you using numerical comparison on strings:

                     } elsif ( $request_key >= 72 && $request_key <= 76 ) {


                         push @return_codec, $codec_r{'B'};
                         next HS;
} elsif ( ( $request_key >= '77' ) and ( $request_key <= '95' )) {

} elsif ( $request_key >= 77 && $request_key <= 95 ) {


                         push @return_codec, $codec_r{'C'};
                         next HS;
} elsif ( ( $request_key >= '96' ) and ( $request_key <= '126' )) {

} elsif ( $request_key >= 96 && $request_key <= 126 ) {


                         push @return_codec, $codec_r{'D'};
                         next HS;
                   }                    }                 }           }
     return @return_codec;
}


John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.                            -- Larry Wall

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to