Of course it is....

Your %hash gets filled with a structure that looks like this:
{ KEY               => VALUE }
{ "@cdr[2,3,6,7]"=> $line    }

Then you take all the values and write them out to a file. Since you never
changed the $line variable you should get the same result in your out file
as you had in the in file. It is good to see perl still works.

Try the following just before the line: $hash{"@cdr[2,3,6,7]"}=$line;

 $line = join(/,/,@cdr);

This way you fill the $line variable with the contents of the just modified
array this should get you the desired result (though there are more stylish
ways of writting it it will get you the result you are looking for)

Rob.


On 8/24/07, Mihir Kamdar <[EMAIL PROTECTED]> wrote:
>
> On 8/24/07, Jeff Pang <[EMAIL PROTECTED]> wrote:
> >
> > 2007/8/24, Mihir Kamdar <[EMAIL PROTECTED]>:
> >
> > >         $cdr[13] = $cdr[6]*5 ; ###Can I do something like this
> >
> > sure,why can't?
>
> Hi,
>
> Please look at my code below and comment. I am trying to manipulate 13th
> field of my record. But I am not getting the desired result in the output.
> The output file is the same as the input file.
>
> #!/usr/bin/perl
>
> use warnings ;
>
> my $file_path =
>
> '/home/user71/RangerDatasource/Customization/TelekomMalaysia/Scripts/Tests/cprogs/files/ratetest';
> my $write_path =
>
> '/home/user71/RangerDatasource/Customization/TelekomMalaysia/Scripts/Tests/cprogs/files/rateop'
> ;
> my %times ;
> my $continue  = 1;
>
> $SIG{INT} = $SIG{TERM} = sub { $continue = 0 };
>
> while ($continue) {
> opendir my $dh, $file_path or die $!;
>        while (my $file = readdir $dh) {
>                my $fname = "$file_path/$file" ;
>                next unless -f $fname;
>                unless (exists $times{$file}){
>                        my $line;
>                        open (my $IN_FILE,"<","$file_path/$file") or die
> $!." file not found" ;
>
>                        while ($line=readline($IN_FILE))
>                        {
>                                my @cdr=split (/,/, $line) ;
>                                $cdr[13] = $cdr[6]*5 ;
>                                $hash{"@cdr[2,3,6,7]"}=$line;
>                        }
>                        close $IN_FILE ;
>
>                        open (my $OUT_FILE,">","$write_path/$file.out") or
> die $!;
>                        while (my($key, $value) = each %hash)
>                        {
>                                print $OUT_FILE $value;
>                        }
>                        close $OUT_FILE;
>                }
>        }
> closedir $dh ;
> }
>
>
>
> Thanks,
> Mihir
>

Reply via email to