Re: comparing hashes

2007-01-15 Thread Rob Dixon

xavier mas wrote:

A Dissabte 13 Gener 2007 18:53, Xavier Noria va escriure:

On Jan 13, 2007, at 6:29 PM, xavier mas wrote:

hello list,

I am trying to find if an element in one primary file (transformed
to array)
is included in two other different secondary files (transformed to
arrays,
too); the result is going to be printed as 1 or 0:

According to the code that's 1 or -1.


...
#creating arrays from its text files
@img_array=; @dict_array=; @in_array=;
#creating hashes from its arrays
foreach $in (@in_array) {chomp($in); $in_hash{$in}= 1;}
foreach $in (@dict_array) {chomp($in);$dict_hash{$in}= 1;}
foreach $in (@img_array) {chomp($in);$img_hash{$in}= 1;}
#searching primary element in secondary hashes
while (($key, $value) = each %in_hash) {
if (exists $dict_hash{$key}) {$dic_flag="1";}else {$dic_flag="-1"}
if (exists $img_hash{$key}) {$img_flag="1";}else {$img_flag="-1";}
#printing result
print "$img_flag, $dic_flag\n";

A bit of air would improve readability, the code is easy but dense
just because of lack of layout.


but it seems 'exists' function doesn't fly to do this -the element
isn't
always found into the secondary hashes. Any suggestion of why it
doesn't and
how to do it?

Besides de potential mismatch given by the fact that the "img" hash
has an "img" flag, but the "dict" hash has a "dic" flag (everything
seems correct in that snippet anyway), I see no problem. Could you
please send a minimal, self-contained code with minimal example files
that let us reproduce the issue?

-- fxn

PS: Please turn strict and warnings on.


thank you for your answer, Xavier.

Here's an example:
in (file, array and hash) contains: "woman, lion, ball"
img (file, array and hash) contains: "ball, dog, cat, lion".
dict (file, array and hash) contains: "house, man, woman, kid, kitchen, lion"


Comparing in with dict ans img, I'll expect as a result (all previous code is 
between the while curly braces): 
-1, 1 
1, 1

1, -1
but the result is, instead:
-1, -1
-1, -1
-1, -1
that means never finds it.

I hope this is enough data.


I think it is very likely that you have leading or (more likely) trailing
whitespace in one or more of your data files. Add this subroutine to your
program

sub readfile {
  my $fh = shift;
  my @data;
  while (<$fh>) {
s/^\s+//;
s/\s+$//;
push @data, $_ if length;
  }
  @data;
}

and then replace your line

@img_array=; @dict_array=; @in_array=;

with

@img_array = readfile(\*IMATGES);
@dict_array = readfile(\*DICT);
@in_array = readfile(\*IN);

and see if you get any improvement.

If you need to post any further code then please edit it so that there is one
statement per line, as otherwise I have to do that myself before I can read it.

HTH,

Rob

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: comparing hashes

2007-01-14 Thread Mumia W.

On 01/13/2007 12:43 PM, xavier mas wrote:

A Dissabte 13 Gener 2007 18:53, Xavier Noria va escriure:

On Jan 13, 2007, at 6:29 PM, xavier mas wrote:

hello list,

I am trying to find if an element in one primary file (transformed
to array)
is included in two other different secondary files (transformed to
arrays,
too); the result is going to be printed as 1 or 0:

According to the code that's 1 or -1.


...
#creating arrays from its text files
@img_array=; @dict_array=; @in_array=;


Here you treat the information as lines.



#creating hashes from its arrays
foreach $in (@in_array) {chomp($in); $in_hash{$in}= 1;}
foreach $in (@dict_array) {chomp($in);$dict_hash{$in}= 1;}
foreach $in (@img_array) {chomp($in);$img_hash{$in}= 1;}
#searching primary element in secondary hashes
while (($key, $value) = each %in_hash) {
if (exists $dict_hash{$key}) {$dic_flag="1";}else {$dic_flag="-1"}
if (exists $img_hash{$key}) {$img_flag="1";}else {$img_flag="-1";}
#printing result
print "$img_flag, $dic_flag\n";

A bit of air would improve readability, the code is easy but dense
just because of lack of layout.


but it seems 'exists' function doesn't fly to do this -the element
isn't
always found into the secondary hashes. Any suggestion of why it
doesn't and
how to do it?

Besides de potential mismatch given by the fact that the "img" hash
has an "img" flag, but the "dict" hash has a "dic" flag (everything
seems correct in that snippet anyway), I see no problem. Could you
please send a minimal, self-contained code with minimal example files
that let us reproduce the issue?

-- fxn

PS: Please turn strict and warnings on.


thank you for your answer, Xavier.

Here's an example:
in (file, array and hash) contains: "woman, lion, ball"
img (file, array and hash) contains: "ball, dog, cat, lion".
dict (file, array and hash) contains: "house, man, woman, kid, kitchen, lion"


Yet here you treat the information as a comma-separated list of words.

Use Data::Dumper to find out what you are putting into your arrays and 
hashes.



[...]




--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: [SPAM DETECT] Re: comparing hashes

2007-01-14 Thread fxn
> A Diumenge 14 Gener 2007 12:33, [EMAIL PROTECTED] va escriure:

> That's the program in full and a sample of the files (same as before):
>
> dict.txt: house, man, woman, kid, kitchen
> img.txt: ball, dog, cat, lion
> in.txt: woman, lion, dog

I'll stop here, please if any other regular wants to take over the thread
feel free.

-- fxn



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: [SPAM DETECT] Re: comparing hashes

2007-01-14 Thread xavier mas
A Diumenge 14 Gener 2007 12:33, [EMAIL PROTECTED] va escriure:
> > A Diumenge 14 Gener 2007 11:20, Xavier Noria va escriure:
> >> Xavier, this is being inefficient.
> >>
> >> If you don't send a minimal example together with data example that
> >> reproduces the issue this is a come and go of second-guesses, which
> >> is a waste of time. Please send them so we can go straight to
> >> understand what happens.
> >>
> >> -- fxn
> >
> > Thank you for your interest, Xavier, but actually that's all what's
> > about. I
> > can send you the long text files (about 3 000 entries each one), but the
> > program the whole program is the one I send (with the string and file
> > handlers pointing to the files). The output of that small program is also
> > just a printing to an output file.
> >
> > What else do you need?
>
> Your problem explanation is not self-contained. It could happen that the
> status of open() is not checked, it could happen that files have different
> newline conventions and some lines had spurious CRs whereas some others
> don't, the files could have the wrong name in the script, a thousand
> possibilities we are not going to explore by trial and error trough
> email
>
> This is a list where people have years of experince debugging by email and
> IRC, please just follow our advice, let us guide the debugging.
>
> Please send a self-contained snippet that reproduces the issue. Turn
> strict and warnings on, and cut the minimal lines of your data files that
> reproduce the problem. I say minimal so we can focuse on the problem, this
> needs some little effort from your side. If you can, upload them somewhere
> and post links to the files so that newlines, non-ascii, etc. is
> preserved.
>
> -- fxn

Xavier,

That's the program in full and a sample of the files (same as before):

dict.txt: house, man, woman, kid, kitchen
img.txt: ball, dog, cat, lion
in.txt: woman, lion, dog

use warnings;
use strict;

#variables declaration
my $img;
my $dict;
my $in;
my @img_array;
my @dict_array;
my @in_array;
my %in_hash;
my %dict_hash;
my %img_hash;
my $value;
my $key;
my $dict_flag;
my $img_flag;
my $projecte_out;

#creating arrays
$img="/home/xavier/Documents/Informàtica/lemes_nous/img.txt";
$dict="/home/xavier/Documents/Informàtica/lemes_nous/dict.txt";
$in="/home/xavier/Documents/Informàtica/lemes_nous/in.txt";
open (IMATGES, $img);open (DICT, $dict);open (IN, "$in");
@img_array=; @dict_array=; @in_array=;
close(IMATGES); close(DICT); close(IN);
foreach $in (@in_array) {chomp($in); $in_hash{$in}= 1;}
foreach $in (@dict_array) {chomp($in);$dict_hash{$in}= 1;}
foreach $in (@img_array) {chomp($in);$img_hash{$in}= 1;}

#searching entries
while (($key, $value) = each %in_hash) {
if (exists $dict_hash{$key}) {$dict_flag="1";}
else {$dict_flag="-1"}
if (exists $img_hash{$in}) {$img_flag="1";}
else {$img_flag="-1";}

#printng results
if ($img_flag eq "1" && $dict_flag eq "-1") {
$projecte_out= "I1D0\n"; print  $projecte_out;}
if ($img_flag eq "1" && $dict_flag eq "1") {
$projecte_out= "I1D1\n"; print  $projecte_out;}
if ($img_flag eq "-1" && $dict_flag eq "-1") {
$projecte_out= "I0D0\n"; print  $projecte_out;}
if ($img_flag eq "-1" && $dict_flag eq "1") {
$projecte_out= "I0D1\n"; print  $projecte_out;}
}

and this are the results: 
I0D0
I0D0
I0D0

Cheers, 

-- 
Xavier Mas

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: comparing hashes

2007-01-14 Thread fxn
> A Diumenge 14 Gener 2007 11:20, Xavier Noria va escriure:
>> Xavier, this is being inefficient.
>>
>> If you don't send a minimal example together with data example that
>> reproduces the issue this is a come and go of second-guesses, which
>> is a waste of time. Please send them so we can go straight to
>> understand what happens.
>>
>> -- fxn
> Thank you for your interest, Xavier, but actually that's all what's about.
> I
> can send you the long text files (about 3 000 entries each one), but the
> program the whole program is the one I send (with the string and file
> handlers pointing to the files). The output of that small program is also
> just a printing to an output file.
>
> What else do you need?

Your problem explanation is not self-contained. It could happen that the
status of open() is not checked, it could happen that files have different
newline conventions and some lines had spurious CRs whereas some others
don't, the files could have the wrong name in the script, a thousand
possibilities we are not going to explore by trial and error trough
email

This is a list where people have years of experince debugging by email and
IRC, please just follow our advice, let us guide the debugging.

Please send a self-contained snippet that reproduces the issue. Turn
strict and warnings on, and cut the minimal lines of your data files that
reproduce the problem. I say minimal so we can focuse on the problem, this
needs some little effort from your side. If you can, upload them somewhere
and post links to the files so that newlines, non-ascii, etc. is
preserved.

-- fxn



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: comparing hashes

2007-01-14 Thread xavier mas
A Diumenge 14 Gener 2007 11:20, Xavier Noria va escriure:
> Xavier, this is being inefficient.
>
> If you don't send a minimal example together with data example that
> reproduces the issue this is a come and go of second-guesses, which
> is a waste of time. Please send them so we can go straight to
> understand what happens.
>
> -- fxn
Thank you for your interest, Xavier, but actually that's all what's about. I 
can send you the long text files (about 3 000 entries each one), but the 
program the whole program is the one I send (with the string and file 
handlers pointing to the files). The output of that small program is also 
just a printing to an output file.

What else do you need?
-- 
Xavier Mas

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: comparing hashes

2007-01-14 Thread Xavier Noria

Xavier, this is being inefficient.

If you don't send a minimal example together with data example that  
reproduces the issue this is a come and go of second-guesses, which  
is a waste of time. Please send them so we can go straight to  
understand what happens.


-- fxn


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: comparing hashes

2007-01-14 Thread xavier mas
A Diumenge 14 Gener 2007 06:39, Bill Jones va escriure:
> On 1/13/07, xavier mas <[EMAIL PROTECTED]> wrote:
> > Yes, this is the code I use, but still doesn't work to me and I can't
> > find the cause.
>
> Have you looked the results using Data::Dumper?  Maybe the results
> aren't as expected?
>
> --
> WC (Bill) Jones -- http://youve-reached-the.endoftheinternet.org/
> http://pgp.mit.edu:11371/pks/lookup?op=vindex&search=0x2A46CF06&fingerprint
>=on
No, I didn't. What does Data::Dumper?

-- 
Xavier Mas

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: comparing hashes

2007-01-13 Thread Bill Jones

On 1/13/07, xavier mas <[EMAIL PROTECTED]> wrote:


Yes, this is the code I use, but still doesn't work to me and I can't find the
cause.


Have you looked the results using Data::Dumper?  Maybe the results
aren't as expected?

--
WC (Bill) Jones -- http://youve-reached-the.endoftheinternet.org/
http://pgp.mit.edu:11371/pks/lookup?op=vindex&search=0x2A46CF06&fingerprint=on

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: comparing hashes

2007-01-13 Thread xavier mas
A Dissabte 13 Gener 2007 20:38, John W. Krahn va escriure:
> xavier mas wrote:
> > Here's an example:
> > in (file, array and hash) contains: "woman, lion, ball"
> > img (file, array and hash) contains: "ball, dog, cat, lion".
> > dict (file, array and hash) contains: "house, man, woman, kid, kitchen,
> > lion"
> >
> > Comparing in with dict ans img, I'll expect as a result (all previous
> > code is between the while curly braces):
> > -1, 1
> > 1, 1
> > 1, -1
> > but the result is, instead:
> > -1, -1
> > -1, -1
> > -1, -1
> > that means never finds it.
> >
> > I hope this is enough data.
>
> I simplified your code:
>
> #!/usr/bin/perl
> use warnings;
> use strict;
> use Inline::Files;
>
> #creating hashes from files
> my %in_hash   = map { chomp; $_, 1 } ;
> my %dict_hash = map { chomp; $_, 1 } ;
> my %img_hash  = map { chomp; $_, 1 } ;
>
> #searching primary element in secondary hashes
> while ( my ( $key, $value ) = each %in_hash ) {
> #printing result
> print exists $img_hash{ $key } ? 1 : -1,
>   ', ',
>   exists $dict_hash{ $key } ? 1 : -1,
>   "\n";
> }
>
> __IN__
> woman
> lion
> ball
> __DICT__
> house
> man
> woman
> kid
> kitchen
> lion
> __IMATGES__
> ball
> dog
> cat
> lion
>
>
> And the results I get are (I get the same results before I modified the
> code):
>
> 1, 1
> -1, 1
> 1, -1
>
>
> So are you sure that the code you posted is the code you are using?
>
>
>
>
> John
> --
> Perl isn't a toolbox, but a small machine shop where you can special-order
> certain sorts of tools at low cost and in short order.   -- Larry Wall

Thank you, John.

Yes, this is the code I use, but still doesn't work to me and I can't find the 
cause.

-- 
Xavier Mas

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: comparing hashes

2007-01-13 Thread Xavier Noria

On Jan 13, 2007, at 7:43 PM, xavier mas wrote:


Here's an example:
in (file, array and hash) contains: "woman, lion, ball"
img (file, array and hash) contains: "ball, dog, cat, lion".
dict (file, array and hash) contains: "house, man, woman, kid,  
kitchen, lion"



Comparing in with dict ans img, I'll expect as a result (all  
previous code is

between the while curly braces):
-1, 1
1, 1
1, -1
but the result is, instead:
-1, -1
-1, -1
-1, -1
that means never finds it.

I hope this is enough data.


It is better but not enough. The way you use hashes is apparently  
correct, so perhaps the problem comes from elsewhere. Please send  
self-contained, minimal code that reproduces the issue, not just an  
incomplete subset. Please turn strict and warnings on.


-- fxn




--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: comparing hashes

2007-01-13 Thread John W. Krahn
xavier mas wrote:
> 
> Here's an example:
> in (file, array and hash) contains: "woman, lion, ball"
> img (file, array and hash) contains: "ball, dog, cat, lion".
> dict (file, array and hash) contains: "house, man, woman, kid, kitchen, lion"
> 
> Comparing in with dict ans img, I'll expect as a result (all previous code is 
> between the while curly braces): 
> -1, 1 
> 1, 1
> 1, -1
> but the result is, instead:
> -1, -1
> -1, -1
> -1, -1
> that means never finds it.
> 
> I hope this is enough data.

I simplified your code:

#!/usr/bin/perl
use warnings;
use strict;
use Inline::Files;

#creating hashes from files
my %in_hash   = map { chomp; $_, 1 } ;
my %dict_hash = map { chomp; $_, 1 } ;
my %img_hash  = map { chomp; $_, 1 } ;

#searching primary element in secondary hashes
while ( my ( $key, $value ) = each %in_hash ) {
#printing result
print exists $img_hash{ $key } ? 1 : -1,
  ', ',
  exists $dict_hash{ $key } ? 1 : -1,
  "\n";
}

__IN__
woman
lion
ball
__DICT__
house
man
woman
kid
kitchen
lion
__IMATGES__
ball
dog
cat
lion


And the results I get are (I get the same results before I modified the code):

1, 1
-1, 1
1, -1


So are you sure that the code you posted is the code you are using?




John
-- 
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order.   -- Larry Wall

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: comparing hashes

2007-01-13 Thread xavier mas
A Dissabte 13 Gener 2007 18:53, Xavier Noria va escriure:
> On Jan 13, 2007, at 6:29 PM, xavier mas wrote:
> > hello list,
> >
> > I am trying to find if an element in one primary file (transformed
> > to array)
> > is included in two other different secondary files (transformed to
> > arrays,
> > too); the result is going to be printed as 1 or 0:
>
> According to the code that's 1 or -1.
>
> > ...
> > #creating arrays from its text files
> > @img_array=; @dict_array=; @in_array=;
> > #creating hashes from its arrays
> > foreach $in (@in_array) {chomp($in); $in_hash{$in}= 1;}
> > foreach $in (@dict_array) {chomp($in);$dict_hash{$in}= 1;}
> > foreach $in (@img_array) {chomp($in);$img_hash{$in}= 1;}
> > #searching primary element in secondary hashes
> > while (($key, $value) = each %in_hash) {
> > if (exists $dict_hash{$key}) {$dic_flag="1";}else {$dic_flag="-1"}
> > if (exists $img_hash{$key}) {$img_flag="1";}else {$img_flag="-1";}
> > #printing result
> > print "$img_flag, $dic_flag\n";
>
> A bit of air would improve readability, the code is easy but dense
> just because of lack of layout.
>
> > but it seems 'exists' function doesn't fly to do this -the element
> > isn't
> > always found into the secondary hashes. Any suggestion of why it
> > doesn't and
> > how to do it?
>
> Besides de potential mismatch given by the fact that the "img" hash
> has an "img" flag, but the "dict" hash has a "dic" flag (everything
> seems correct in that snippet anyway), I see no problem. Could you
> please send a minimal, self-contained code with minimal example files
> that let us reproduce the issue?
>
> -- fxn
>
> PS: Please turn strict and warnings on.

thank you for your answer, Xavier.

Here's an example:
in (file, array and hash) contains: "woman, lion, ball"
img (file, array and hash) contains: "ball, dog, cat, lion".
dict (file, array and hash) contains: "house, man, woman, kid, kitchen, lion"


Comparing in with dict ans img, I'll expect as a result (all previous code is 
between the while curly braces): 
-1, 1 
1, 1
1, -1
but the result is, instead:
-1, -1
-1, -1
-1, -1
that means never finds it.

I hope this is enough data.



Greetings,

-- 
Xavier Mas

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: comparing hashes

2007-01-13 Thread Xavier Noria

On Jan 13, 2007, at 6:29 PM, xavier mas wrote:


hello list,

I am trying to find if an element in one primary file (transformed  
to array)
is included in two other different secondary files (transformed to  
arrays,

too); the result is going to be printed as 1 or 0:


According to the code that's 1 or -1.




...
#creating arrays from its text files
@img_array=; @dict_array=; @in_array=;
#creating hashes from its arrays
foreach $in (@in_array) {chomp($in); $in_hash{$in}= 1;}
foreach $in (@dict_array) {chomp($in);$dict_hash{$in}= 1;}
foreach $in (@img_array) {chomp($in);$img_hash{$in}= 1;}
#searching primary element in secondary hashes
while (($key, $value) = each %in_hash) {
if (exists $dict_hash{$key}) {$dic_flag="1";}else {$dic_flag="-1"}
if (exists $img_hash{$key}) {$img_flag="1";}else {$img_flag="-1";}
#printing result
print "$img_flag, $dic_flag\n";


A bit of air would improve readability, the code is easy but dense  
just because of lack of layout.



but it seems 'exists' function doesn't fly to do this -the element  
isn't
always found into the secondary hashes. Any suggestion of why it  
doesn't and

how to do it?


Besides de potential mismatch given by the fact that the "img" hash  
has an "img" flag, but the "dict" hash has a "dic" flag (everything  
seems correct in that snippet anyway), I see no problem. Could you  
please send a minimal, self-contained code with minimal example files  
that let us reproduce the issue?


-- fxn

PS: Please turn strict and warnings on.




--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Comparing Hashes with different keys. How ?

2003-12-16 Thread R. Joseph Newton
John Hennessy wrote:

> Hi, I have two different hashes built from separate data and need to
> find the common then differing items.
>
> $HoA1{$custnum} = [ $uid, $firstname, $lastname ];
> $HoA2{$uid} = [ $custnum, $firstname, $lastname ];
>
> I have looked at examples for "Finding Common or Different Keys in Two
> Hashes" but the keys must be the same.
> To make the keys the same I would like to effect a reverse function but
> only reversing the key and the first value leaving the remaining array
> items in place.
>
> Examples or suggestion would be most appreciated.
> Thanks
>
> John.

my $uids_by_name = {}
foreach $fields_ref  (keys %HoA1) {
  my $uid = $fields_ref->[0];
  my $name_slice = [$fields_ref->[1,2] ];
  $uids_by_name->{$name_slice} = [] unless $uids_by_name->{$name_slice};
  push @{$uids_by_name->{$name_slice}}, $uid;
}

Oooh, yuck!  I just realized that you have a potentially insoluble problem
here.  Since you don't seem to have a cross-reference between custid and
uid, and since names are *never* determinate as references, I can't see any
way to programatically associate the two structures.

Joseph


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




Re: Comparing Hashes with different keys. How ?

2003-12-16 Thread Jenda Krynicky
Date sent:  Tue, 16 Dec 2003 23:36:16 +0800
From:   John Hennessy <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED]
Subject:Comparing Hashes with different keys. How ?

> Hi, I have two different hashes built from separate data and need to
> find the common then differing items.
> 
> $HoA1{$custnum} = [ $uid, $firstname, $lastname ];
> $HoA2{$uid} = [ $custnum, $firstname, $lastname ];
> 
> I have looked at examples for "Finding Common or Different Keys in Two
> Hashes" but the keys must be the same. To make the keys the same I
> would like to effect a reverse function but only reversing the key and
> the first value leaving the remaining array items in place.

my %HoA2r;
while (my ($key, $value) = each %HoA2) {
$HoA2r{$value->[0]} = [ $key, $value->[1], $value->[2]];
}

You should probably check whether
exists $HoA2r{$value->[0]}
and handle the duplicate '$custnum's in the %HoA2 as well.

Jenda
= [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery


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




Re: Comparing Hashes with different keys. How ?

2003-12-16 Thread Rob Dixon
John Hennessy wrote:
>
> Hi, I have two different hashes built from separate data and need to
> find the common then differing items.
>
> $HoA1{$custnum} = [ $uid, $firstname, $lastname ];
> $HoA2{$uid} = [ $custnum, $firstname, $lastname ];
>
> I have looked at examples for "Finding Common or Different Keys in Two
> Hashes" but the keys must be the same.
> To make the keys the same I would like to effect a reverse function but
> only reversing the key and the first value leaving the remaining array
> items in place.

Hi John.

I would start by pulling out the lists of Customer Numbers and User IDs
from the two hashes like this:

  my @custnum1 = keys %HoA1;
  my @uid1 = map { $Hoa1{$_}[0] } @custnum1;

  my @uid2 = keys %HoA1;
  my @custnum2 = map { $Hoa1{$_}[0] } @uid2;

Then you only have the job of finding differences and commonalities
between @custnum1/@custnum2 and @uid1/@uid2.

HTH,

Rob



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




Re: Comparing Hashes with different keys. How ?

2003-12-16 Thread James Edward Gray II
On Dec 16, 2003, at 9:36 AM, John Hennessy wrote:

Hi, I have two different hashes built from separate data and need to 
find the common then differing items.

$HoA1{$custnum} = [ $uid, $firstname, $lastname ];
$HoA2{$uid} = [ $custnum, $firstname, $lastname ];
I have looked at examples for "Finding Common or Different Keys in Two 
Hashes" but the keys must be the same.
To make the keys the same I would like to effect a reverse function 
but only reversing the key and the first value leaving the remaining 
array items in place.
What defines likeness or difference?  Do we just need to check one 
field, two fields together or what?

James

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