Your idea should work pretty well assuming that you are 100% sure that the
thing in field 7 really is a number, you might get strange results if field
7 is empty or somehting else then a number.

As for how to handle the files that is really up to you and the environment
you work in... if your files are masive things of several hundreds of Mb
each you might not want to place them completely in memory, if they are
changed by other processes you might want to use some form of a locking
scheme while handeling them. Etc, etc...



On 8/24/07, Mihir Kamdar <[EMAIL PROTECTED]> wrote:
>
> Hi,
>
> I have a csv file. I wanted to do some calculations on some of its fields,
> like multiplying the 7th field with the 13th field and overwriting the
> 13th
> field with the answer of my calculation.
>
> Regarding this, can I do the calculations on the input file and overwrite
> it
> after calculating, or I will have to open the output file and write into
> it?
> I am asking this because I will have several files in the directory. So, I
> will have to read the directory using readdir,  and process each file. It
> is
> better if I open the file in read-write mode, process it and overwrite the
> file. Just wanted to know if it is safe?
>
> Please guide on how to get started with this?
>
> Also can I do something like below:-
>
>
> while ($line=readline($IN_FILE))
>    {
>        my @cdr=split (/,/, $line) ;
>        $cdr[13] = $cdr[6]*5 ; ###Can I do something like this
>    }
>
> Thanks,
> Mihir
>

Reply via email to