it seems i didn't re-all on the email before that one, for the list:

Well, here's discussion about #2:
http://tinyurl.com/26buovt
Let me know if you need me to Google #1 up for you as well.

Btw, the Unix way would be something like:
awk ....
Ah hell what am I thinking.
http://www.unix.com/shell-programming-scripting/99929-need-compare-two-csv-files-values-write-into-another-csv-file.html

I think the point is, with most things, someone has already done it. So,
what's the point of reinventing the wheel when Google takes two seconds. Try
it. Actually, for perl stuff, I've had better luck with Bing fwiw.
Seriously, try to find it, stitch some stuff together, bang your head for a
few hours debugging and then, when you've picked your medicine cabinet of
all pain killers, smoked your last cigarette... after all of that, come back
here with what you've got, tell us about what you've tried (and a bit about
your headache) and we'll see what we can do.

On Mon, Nov 1, 2010 at 7:29 AM, shawn wilson <ag4ve...@gmail.com> wrote:

> as i said, google. i'm not taking my time to write it for you, but someone
> already has:
> http://csvdiff.sourceforge.net/
> also, this was linked to from a perlmonks node:
> http://www.perlmonks.org/index.pl?node_id=705049
> which has someone's shorter script for you. he doesn't do 'exactly' what
> you wrote, but with that and my first email, you should be able to hack
> something reasonable together.
>
> also, 'let me google that for you' says:
> http://www.lmgtfy.com/?q=perl+compare+csv
> fifth link down is the perlmonks, and the one before that is the page of
> developer of csvdiff.
>
> also, if you aren't trying to learn and just want to get something done,
> you have the awk script i found for you in the last exchange. good luck.
>
>
> On Mon, Nov 1, 2010 at 6:44 AM, Brian <brian5432...@yahoo.co.uk> wrote:
>
>> Thanks Shawn, due to head injuries in a car crash, if I don't do something
>> (as involved as this) every single day I forget all I've learned.
>> I did have examples to work from but they were lost in a system crash that
>> totalled my hard drive.
>> Having read back my op, maybe I need to tidy up what I'm asking :-)
>> File 1 will only have 2 comma separated values to deal with, whilst file 2
>> will have 3 or more, so I take it this would be entering the realms of
>> arrays?
>> I don't mind if the output goes directly to file 2, but as it is so easy
>> to do a simple command line copy of one file to another, maybe for the sake
>> of sanity it might be better to handle both input files and output to a 3rd
>> work file, which can be renamed later.
>>
>> Also, what would be the best parms to open the necessary input files?
>>
>> thanks
>> Brian
>>
>> ------------------------------
>> *From:* shawn wilson <ag4ve...@gmail.com>
>> *To:* Jim Gibson <jimsgib...@gmail.com>
>> *Cc:* beginners@perl.org
>> *Sent:* Mon, November 1, 2010 9:07:36 AM
>> *Subject:* Re: Compare files
>>
>> I personally don't under #3. I would do something like:
>>
>> while( my ($key, $value) = each %file2) {
>> print "$key,$value" if( !defined( $file1{ $key } ) );
>> print "$key,$file1{ $key } if( defined( $file1{ $key } ) );
>> }
>> That assumes that the keys are exact between files.
>>
>> However, as I wrote this, I think what you were saying is to pop off the
>> values as you print and then loop the remaining?
>> On Nov 1, 2010 2:46 AM, "Jim Gibson" <jimsgib...@gmail.com> wrote:
>> > At 9:34 PM +0000 10/31/10, Brian wrote:
>> >>Thanks for the previous help, that triggered a few dormant grey cells
>> :-)
>> >>and leads me to another question.
>> >>
>> >>I would like to compare 2 (unsorted) csv files..
>> >>
>> >>file 1 contains
>> >>
>> >>fredbloggs,0
>> >>joebloggs,3
>> >>joeblow,6
>> >>
>> >>file 2
>> >>
>> >>fredbloggs,1
>> >>joebloggs,4
>> >>
>> >>replace the value in file 2 with the value in file 1.
>> >>if the item in file 1 doesn't exist in file 2, insert/append the line
>> >>
>> >>so that
>> >>
>> >>file 2 becomes
>> >>
>> >>fredbloggs,0
>> >>joebloggs,4
>> >>joeblow,6
>> >
>> > How big are your files? If they are not too big, I would do the
>> following:
>> >
>> > 1. Read file 1, remove the end-of-line (EOL) character from each
>> > line, split the line into two strings, save the two strings in a hash.
>> > 2. Read file 2, remove the EOL, split the line, check to see if the
>> > key exists in the hash and, if it does, replace the second field with
>> > the corresponding hash value. write out the line, and (here is the
>> > tricky part) delete the hash entry.
>> >
>> > 3. Iterate over the hash entries that remain and add them to the end
>> > of the file.
>> >
>> > Note: this will only work if the key values in file 1 and 2 are unique.
>> >
>> > Can you write the code for each of these steps?
>> >
>> > For information on the Perl functions you need, see the following:
>> >
>> > perldoc -f open
>> > perldoc -f chomp
>> > perldoc -f split
>> > perldoc -f exists
>> > perldoc -f delete
>> >
>> > --
>> > Jim Gibson
>> > j...@gibson.org
>> >
>> > --
>> > To unsubscribe, e-mail: beginners-unsubscr...@perl.org
>> > For additional commands, e-mail: beginners-h...@perl.org
>> > http://learn.perl.org/
>> >
>> >
>>
>>
>

Reply via email to