good chemistry is complicated,and a little bit messy -LW PerlMonks

### reference problem

 on Jan 09, 2003 at 14:20 UTC Need Help??
toadi has asked for the wisdom of the Perl Monks concerning the following question:

use strict; use Tie::IxHash; tie( my %csv, 'Tie::IxHash', 'one' => undef, 'two' => undef, 'three' => undef, 'four' => undef, 'five' => undef, ); my %login; { my %dummy = %csv; \$dummy{one} = "11"; \$dummy{two} = "12"; \$dummy{three} = "13"; \$dummy{four} = "14"; \$dummy{five} = "15"; \$login{1} = \%dummy; } { my %dummy = %csv; \$dummy{one} = "11"; \$dummy{two} = "12"; \$dummy{three} = "23"; \$dummy{four} = "14"; \$dummy{five} = "25"; \$login{2} = \%dummy; } { my %dummy = %csv; \$dummy{one} = "31"; \$dummy{two} = "12"; \$dummy{three} = "23"; \$dummy{four} = "34"; \$dummy{five} = "25"; \$login{2} = \%dummy; while (my (\$k,\$v) = each %login) { print "NEW\n"; while ( my (\$k, \$v) = each %{dummy} ) { print \$k." =". \$v ."\n"; + } } }
I want the output to be:
NEW one =11 five =12 three =13 two =13 four =14 five =15 NEW one =31 five =25 three =23 two =12 four =34 five =25
Problem is that i want to loop login and if the key of login matches with one before it should be a hash union and when it doesn't matches just print the hash it contains.

If you need some more info pm me... I'm going to try to find the solution too :p But have been trying many options and I'm a bit stuck :(

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

Replies are listed 'Best First'.
Re: reference problem
by toadi (Chaplain) on Jan 09, 2003 at 14:24 UTC
Solved it I think:
use strict; use Tie::IxHash; my %login; { tie( my %csv, 'Tie::IxHash', 'one' => undef, 'two' => undef, 'three' => undef, 'four' => undef, 'five' => undef, ); \$csv{one} = "11"; \$csv{two} = "12"; \$csv{three} = "13"; \$csv{four} = "14"; \$csv{five} = "15"; \$login{1} = \%csv; } { tie( my %csv, 'Tie::IxHash', 'one' => undef, 'two' => undef, 'three' => undef, 'four' => undef, 'five' => undef, ); \$csv{one} = "11"; \$csv{three} = "23"; \$csv{four} = "14"; \$csv{five} = "25"; \$login{2} = \%csv; } { tie( my %csv, 'Tie::IxHash', 'one' => undef, 'two' => undef, 'three' => undef, 'four' => undef, 'five' => undef, ); \$csv{one} = "31"; \$csv{two} = "12"; \$csv{three} = "23"; \$csv{five} = "25"; my \$match = "2"; while (my (\$k,\$v) = each %login) { if (\$k eq \$match) { my %union; print "MATCH\n"; while ( my (\$k, \$v) = each %\$v ) { \$union{\$k} = \$v; } while ( my (\$k, \$v) = each %csv ) { \$union{\$k} = \$v; } print map{\$_ ."=". \$union{\$_} ."\n"} keys %union; } else { print "NO MATCH\n"; while ( my (\$k, \$v) = each %\$v ) { print \$k ."=". \$v."\n"; } } } }
Mhh the union part doesn't work like i want to. Empty elements in it?
Off course suggestions howto improve the rest of the code are also welcome!!

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

Create A New User
Node Status?
node history
Node Type: perlquestion [id://225543]
Approved by grinder
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (2)
As of 2017-08-20 00:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
Who is your favorite scientist and why?

Results (312 votes). Check out past polls.

Notices?