On 8/27/07, Chas Owens <[EMAIL PROTECTED]> wrote: > > On 8/27/07, Mihir Kamdar <[EMAIL PROTECTED]> wrote: > snip > > for my $len (reverse $shortest .. > $longest) { > > my $key = substr $cdr[3],0,$len; > > last if $rate = $prefix_to_rate{$key}; > > if (defined $rate) { > > $cdr[13] =($cdr[6]/20)*$rate ; > > } > > } > snip > > The last will execute if $rate is set, so the "if (defined" will never > be true (unless rate is 0, which I would assume is an error). You > either need to move the "if (defined" outside of the for loop or you > need to change the "last if" to > > if (exists $prefix_to_rate{$key}) { > $cdr[13] = $cdr[6]/20*$prefix_to_rate{$key}; > last; > } > > Also, you need to work on your indenting. It is all over the place > (which is probably why your if statement is in the wrong place). You > might consider installing perltidy and running it on your code. > Hi Chas,
I modified it like below:- while ($line=readline($IN_FILE)) { my @cdr=split (/,/, $line) ; my $rate; if($cdr[22] eq "Budget-IDD" ) { for my $len (reverse $shortest .. $longest) { my $key = substr $cdr[3],0,$len; last if $rate = $prefix_to_rate{$key}; } if (defined $rate) { $cdr[13] = ($cdr[6]/20)*$rate ; } } $line = join(",",@cdr); [EMAIL PROTECTED],3,6,7]}=$line; } close $IN_FILE ; Still not getting the result? Thanks..