David wrote:

> 
> does the following do what you want:
> 
> sub update_categories{
>         my $data_files = shift;
>         my $main_cat   = shift;
>         my $sub_cat    = shift;
>         open(CAT,$data_files) || die $!;
>         while(<CAT>){
>                 close(CAT) and return if(/$main_cat\::$sub_cat/); #-- 1.
>         }
>         close(CAT);
>         open(CAT,">>$data_files") || die $!;
>         print CAT "$main_cat\::$sub_cat\n"; #-- 2.
>         close(CAT);
> }
> 
> 1. return and do nothing if $main_cat::$sub_cat already exists in the file
> 2. add to the end of the data file if $main_cat::$sub_cat does not exists

thinking about it after a while, probably better as:

sub update_categories{
        my $data_files = shift;
        my $main_cat   = shift;
        my $sub_cat    = shift;
        open(CAT,"+>>$data_files") || die $!;
        while(<CAT>){
                close(CAT) and return if(/$main_cat\::$sub_cat/);
        }
        print CAT "$main_cat\::$sub_cat\n";
        close(CAT);
}

david

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to