Thanks David, that solved my problem.

-----Original Message-----
From: Wagner-David [mailto:[EMAIL PROTECTED]]
Sent: Friday, December 07, 2001 12:29 PM
To: Epperson, Randall W; Perl Beginners list (E-mail)
Subject: RE: Problem with replacing hash elements


        Here is a shot which works with data provided, but others may
see other real problems with it. When it comes to hash and ref to to
array within hash, I have not the best understanding.

 use strict "refs";                                                
 #-----------------------------------------------------------------
 # define some variables                                           
 #-----------------------------------------------------------------
# $notify_file = "/usr/local/bin/unix_notify";                      
# open(NOTIFY, $notify_file) or                                     
#    die "$0: cannot open $notify_file: $!\n";                      
                                                                   
 # load the notify file into a hash -------------------------------
while ( <DATA> ) {

   chomp;                       # remove newline char              
   next if /^\s*#/;             # skip comments                    
   next unless s/^(.*?):\s*//;  # look for xxx: yyyy  format       
   $notify_email{$1} = [ split /;/ ];                              
 }                                                                 

foreach $key ( keys(%notify_email) ) {

   print "the notify code is $key\n";
   my $MyOffset = 0;                            
   foreach my $element ( @{ $notify_email{$key} } ) {

      if (exists $notify_email{$element}) { 
           # use of splice to replace which may not work correctly if
another array, but like said
           # works with data provided.
           #
         splice( @{ $notify_email{$key}}, $MyOffset, 1, (@{
$notify_email{$element} }) ); 
       }
      $MyOffset++;                                                     
    }                                                         
 }         
                                                     
print "\n";
foreach $key ( keys(%notify_email) ) {

   print "the notify code is $key\n";
   foreach my $element ( @{ $notify_email{$key} } ) {

      print "  $element\n";              
    }                                                         
 }                                                              
__DATA__
e-internalteam: e-randy;e-joel;e-darren
e-randy: [EMAIL PROTECTED]
e-joel: [EMAIL PROTECTED]
e-darren: [EMAIL PROTECTED]
^--- Script ends here

Output:
the notify code is e-internalteam
  [EMAIL PROTECTED]
  [EMAIL PROTECTED]
  [EMAIL PROTECTED]
the notify code is e-joel
  [EMAIL PROTECTED]
the notify code is e-darren
  [EMAIL PROTECTED]
the notify code is e-randy
  [EMAIL PROTECTED]

-----Original Message-----
From: Epperson, Randall W [mailto:[EMAIL PROTECTED]]
Sent: Friday, December 07, 2001 07:48
To: Perl Beginners list (E-mail)
Subject: Problem with replacing hash elements


Greetings

Here is the format of my notify file:
e-internalteam: e-randy;e-joel;e-darren
e-randy: [EMAIL PROTECTED]
e-joel: [EMAIL PROTECTED]
e-darren: [EMAIL PROTECTED]

I'm trying to build a hash of arrays that looks like this:
e-internalteam [EMAIL PROTECTED] [EMAIL PROTECTED] [EMAIL PROTECTED]
e-randy [EMAIL PROTECTED]
e-joel [EMAIL PROTECTED]
e-darren [EMAIL PROTECTED]

Here is my code:

 #!/usr/bin/perl -w                                                
 use strict "refs";                                                
 #-----------------------------------------------------------------
 # define some variables                                           
 #-----------------------------------------------------------------
 $notify_file = "/usr/local/bin/unix_notify";                      
 open(NOTIFY, $notify_file) or                                     
    die "$0: cannot open $notify_file: $!\n";                      
                                                                   
 # load the notify file into a hash -------------------------------
 while ( <NOTIFY> )                                                
 {                                                                 
   chomp;                       # remove newline char              
   next if /^\s*#/;             # skip comments                    
   next unless s/^(.*?):\s*//;  # look for xxx: yyyy  format       
   $notify_email{$1} = [ split /;/ ];                              
 }                                                                 
                                                                   
 # insure any notify codes are resolved                            
 foreach $key ( keys(%notify_email) )                              
 {                                                                 
     print "the notify code is $key\n";                            
     foreach my $element ( @{ $notify_email{$key} } )
     {                                                         
         print "the email address is $element\n";              
         if (exists $notify_email{$element})                   
         { push my @new_array, (@{ $notify_email{$element} });  <===
problem here
           print "new array is @new_array\n";                  
         }                                                     
     }                                                         
 }                                                             
                                                               
 close NOTIFY;

My problem seems to be that I cannot replace the element in the 
first hash entry with its value from later hash entries. I thought
if I could create a new_array and then reassign the first hash
entry...???

Any and all suggestions are welcome.


thanks...randy epperson
Lands' End Unix sysadmin
[EMAIL PROTECTED]

Don't anthropomorphize computers. They hate that.

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

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

Reply via email to