Christophe

I think using Tie::File is overkill here. Try this:

#   Merge the two files into a single hash
#
    for $file ( 'file2.dat', 'file1.dat' )
    {
        open FILE, "< $file";

        while ( <FILE> )
        {
            chomp;
            ($key, $val) = split /:\s+/;
            $data{$key} = $val;
        }

        close FILE;
    }

#   and splat it out again
#
    open FILE, "> file3.dat";
    printf FILE "%s: %s\n", $_, $data{$_}
            for (sort keys %data);
    close FILE;

I'm not sure about your 'some text'. If you're allowing comment lines
starting with a hash then

    next if /^#/;

at the start of the inner loop will do. Now if you want the comments
retaining, that's another matter :))

I never like posting just a solution on the beginners' group, but I don't
think I'm doing anything obscure here that needs explaining. Tell me if I'm
wrong.

HTH.

Cheers,

Rob

----- Original Message -----
From: "folschette" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, October 15, 2002 10:56 AM
Subject: file to file copy


> hello,
> i have to write a perl script which copies text from one file to another
but
> only if the text is not exisiting yet.
> For example:
> in file1:
> word: moon
> word2: sky
> ...
> the same syntax for every line
>
> in file2:
> #some text
> word: honey
> word3: lol
> word4: mu
> ...
> as well the same syntax for every line
>
> so now i want to merge file1 into file2, so that word: honey will be
> replaced by word: moon and word2: sky will be appended to file2.
> i have written the following script but i've got little problem with it,
can
> someone help me? or test it?
>
> thanx,  christophe folschette


----------------------------------------------------------------------------
----


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


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

Reply via email to