Jerry Rocteur wrote:
Hi,

I came across this problem and thought I'd run it by the list so that perhaps 
someone can explain to me what is going on

Given a script with the following hash definition

#!/usr/bin/perl

use warnings;
use strict;

my %sib_master_hoa  = (
        XXXX            => [ 'XXXX <type>' ] ,
        XXXX_ERSALL     => [ 'XXXX <type>', 'ERS CRCODOSS <type>', 'ERS ENVDOSS 
<type>', 'ERS ENVVAL <type>' ],
        XXXX_ERSOTHERS  => [ 'XXXX <type>', 'ERS CRCODOSS <type>', 'ERS ENVVAL 
<type>' ],
);

sub AddGroup {
    my ($sib_user, $sib_profile, $sib_sibprofx) = @_;
    #
    for my $profile ( @{ $sib_master_hoa{$sib_profile}  } ) {

    for my key ( @{ $sib_master_hoa{$sib_profile}  } ) {
          my $profile = $key;

# See `perldoc perlsyn` and search for /Foreach Loops/;

        $profile =~ s/<type>/$sib_sibprofx/g;
        print  "-A $sib_user -g $profile\n";
    }

}                                                                               
                                 #
#  Main             MAIN                                                        
                                   #

AddGroup("jerry","XXXX","ONE");
AddGroup("laurence","XXXX","TWO");
AddGroup("ralf","XXXX_ERSALL","ONE");
AddGroup("randal","XXXX_ERSALL","TWO")
#EOF

__END__


The output I get is:

-A jerry -g XXXX ONE
-A laurence -g XXXX ONE
-A ralf -g XXXX ONE
-A ralf -g ERS CRCODOSS ONE
-A ralf -g ERS ENVDOSS ONE
-A ralf -g ERS ENVVAL ONE
-A randal -g XXXX ONE
-A randal -g ERS CRCODOSS ONE
-A randal -g ERS ENVDOSS ONE
-A randal -g ERS ENVVAL ONE

The values in the array in the hash are being changed but not by me ?

I've run this on  perl, v5.8.0 built for PA-RISC1.1-thread-multi and  perl, 
v5.6.1 built for x86_64-linux with the
same result.

If I define the hash inside the function I don't get the problem but I'm still 
confused about what is going on. I've
never seen anywhere yet that I can't define this kind of hash globally. This of 
course does not mean no one has said
it.

Thanks in advance for any ideas.

You're welcome :)


--
Just my 0.00000002 million dollars worth,
  Shawn

Programming is as much about organization and communication
as it is about coding.

I like Perl; it's the only language where you can bless your
thingy.

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to