Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Re: Uniion of 2 hashes don't work.

by toadi (Chaplain)
on Jan 10, 2003 at 13:20 UTC ( #225784=note: print w/ replies, xml ) Need Help??


in reply to Re: Uniion of 2 hashes don't work.
in thread Union of 2 hashes don't work.

Well I actually did it on a other way...

- I had 2 queries from a db.
- I wanted to write the results in a csv(fixed order so tie).
- But in the first query i had a key login and if this key existed in second query I wanted the data from both queries as a union on one line in the csv.(both had common fields and unique fields to the both queries)

I solved it on db-level:
- I made a new table in oracle where i put the data from query one. Then do a insert or update(to login) with second query.(first i did it with tempory tables in memory, but dumped that idea).
- Finally I read out that table and make the csv.

This solution is also good for knowing on which day what data should be in that csv. If something went wrong with creating the csv and/or sending it to the outside party. I easily can redo this step, because of this table.


For the ones who would be interested hacked a small sample, how i could do it on perl-level:

# record 1 $login = "me"; $name = "toadi"; $email = "toadi@toadi.be"; $contract = "SERVICE"; $csv{$login}{name}=$name; $csv{$login}{email}=$email; $csv{$login}{contract}=$contract; # record 2 $login = "u"; $name = "other one"; $email = "other@other.be"; $contract = "Programming"; $csv{$login}{name}=$name; $csv{$login}{email}=$email; $csv{$login}{contract}=$contract; foreach $login ( keys %csv ) { print "$csv{$login}{name},$csv{$login}{email},$csv{$login}{rek +nr},$csv{$login}{contract}\n"; }
So if the key exits, it will write over the needed values. If key not exits it wil make a new entry...

--
My opinions may have changed,
but not the fact that I am right


Comment on Re: Re: Uniion of 2 hashes don't work.
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://225784]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (9)
As of 2014-07-14 09:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (257 votes), past polls