Front page | perl.beginners |
Postings from September 2009
Strange Data space wipe out with hashes
Thread Next
From:
Jerry Rocteur
Date:
September 17, 2009 05:16
Subject:
Strange Data space wipe out with hashes
Message ID:
53635.153.98.68.197.1253189728.squirrel@webmail.rocteur.com
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} } ) {
$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
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.
Jerry
Thread Next
-
Strange Data space wipe out with hashes
by Jerry Rocteur