I rewrite our code like this and it works !

#!/usr/bin/perl
use strict;
my @array;
my $count = 0;
my $maxCount = 1;

while ($count < $maxCount){
        $count++;
    my $myHash = &getHash;
        
    foreach my $key (keys %$myHash )
    {
       print "THIS WORKS: $key $myHash->{$key}\n";
    }

    # Now assign the hash to my array
    $array[$count] = $myHash;

    my $newHash = $array[$count];
    foreach my $key (keys %$newHash )
    {
        print "THIS WORKS AS WELL: $key $newHash->{$key}\n";
    }
}

sub getHash{
        my $href={
                'Mon' => '01',
                'Tue' => '02',
                'Wed' => '03'
        };
        return $href;
}
__END__

The output is :

THIS WORKS: Wed 03
THIS WORKS: Tue 02
THIS WORKS: Mon 01
THIS WORKS AS WELL: Wed 03
THIS WORKS AS WELL: Tue 02
THIS WORKS AS WELL: Mon 01


HTH,

José.

-----Original Message-----
From: Simon Tomlinson [mailto:[EMAIL PROTECTED]] 
Sent: Wednesday, September 18, 2002 3:18 PM
To: Nikola Janceski <nikola_janceski; [EMAIL PROTECTED]
Subject: RE: Array of Hashes




Apologies, that was bad typing in my email.  I rearrange the algorithm to make it 
easier to read.  Here is my exact source and the exact output.  Even without the space 
there, it still doesn't work!!

Any ideas?
Simon.


sub getEvents
{
  my @rows = &getDBTable($tbl_events);
  my @colDefs = ("");
  @colDefs = split(",",substr($rows[0], index($rows[0],":")+1));
  my $rowCount = -1;
  my @rowCols;

  foreach $row (@rows)
  {
      if ($rowCount > -1)
      {
        my %tempCols = &getCols($row, @colDefs);

        foreach $key (keys %tempCols)
        {
            print "WORKS: $key $tempCols{$key}<br>\n";
        }
        $rowCols[$rowCount] = %tempCols;
      }

       my %event = $rowCols[$rowCount];
       foreach $key (keys %event)
       {
           print "DOESN'T WORK: $key $event{$key}<br>\n";
       }

     $rowCount = $rowCount + 1;
  }
  return @rowCols;
}


DOESN'T WORK:
WORKS: description Rehearsal
WORKS: event_time 18:30
WORKS: event_id 1
WORKS: event_date 07-09-2002
DOESN'T WORK: 4/8
WORKS: description Church Service
WORKS: event_time 11:00
WORKS: event_id 2
WORKS: event_date 08-09-2002
DOESN'T WORK: 4/8
WORKS: description Rehearsal
WORKS: event_time 18:30
WORKS: event_id 3
WORKS: event_date 14-09-2002
DOESN'T WORK: 4/8
WORKS: description Church Service
WORKS: event_time 11:00
WORKS: event_id 3
WORKS: event_date 15-09-2002
DOESN'T WORK: 4/8

Regards
Simon



                                                                                       
                                                                           
                      Nikola Janceski                                                  
                                                                           
                      <nikola_janceski@su        To:       Simon Tomlinson/DMGGM/DMG 
UK/DeuBa@DMG UK, [EMAIL PROTECTED]                                          
                      mmithq.com>                cc:                                   
                                                                           
                                                 Subject:  RE: Array of Hashes         
                                                                           
                      18/09/2002 14:11                                                 
                                                                           
                                                                                       
                                                                           
                                                                                       
                                                                           




you have a space that shouldn't be there:

>         print "THIS DOESN'T WORK: $key $newHash {$key}\n";
                                                 ^
should be:
         print "THIS DOESN'T WORK: $key $newHash{$key}\n";

> -----Original Message-----
> From: Simon Tomlinson [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, September 18, 2002 9:06 AM
> To: [EMAIL PROTECTED]
> Subject: Array of Hashes
>
>
> Hi
>
> I want to put a hash into each element of an array.  I do it like the 
> following bit of code.  When I iterate round my hash before putting it 
> in the array of the hash values/keys are there.  However, when I 
> iterate through the hash after putting it in the array all i get is 
> '4/8' as the ouput.
>
> I am sure this is very simple and I'm doing something stupid.  Does 
> anyone have any ideas?
>
> Thanks in advance,
> Simon.
>
> my @array
> my $count = 0;
> my $maxCount = 4;
>
> while $count < $maxCount
> {
>     my %myHash = &getHash;
>
>     foreach $key (keys %myHash )
>     {
>        print "THIS WORKS: $key $myHash{$key}\n";
>     }
>
>     # Now assign the hash to my array
>     $array[$count] = %myHash;
>
>     my %newHash = $array[$count];
>     foreach $key (keys %newHash )
>     {
>         print "THIS DOESN'T WORK: $key $newHash {$key}\n";
>     }
> }
>
>
> --
>
> This e-mail may contain confidential and/or privileged information. If 
> you are not the intended recipient (or have received this e-mail in 
> error) please notify the sender immediately and destroy this e-mail. 
> Any unauthorized copying, disclosure or distribution of the material 
> in this e-mail is strictly forbidden.
>
>
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>

----------------------------------------------------------------------------
--------------------
The views and opinions expressed in this email message are the sender's own, and do 
not necessarily represent the views and opinions of Summit Systems Inc.


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






--

This e-mail may contain confidential and/or privileged information. If you are not the 
intended recipient (or have received this e-mail in error) please notify the sender 
immediately and destroy this e-mail. Any unauthorized copying, disclosure or 
distribution of the material in this e-mail is strictly forbidden.



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



**** DISCLAIMER ****

"This e-mail and any attachment thereto may contain information which is confidential 
and/or protected by intellectual property rights and are intended for the sole use of 
the recipient(s) named above. 
Any use of the information contained herein (including, but not limited to, total or 
partial reproduction, communication or distribution in any form) by other persons than 
the designated recipient(s) is prohibited. 
If you have received this e-mail in error, please notify the sender either by 
telephone or by e-mail and delete the material from any computer".

Thank you for your cooperation.

For further information about Proximus mobile phone services please see our website at 
http://www.proximus.be or refer to any Proximus agent.


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

Reply via email to