Front page | perl.beginners |
Postings from September 2009
Re: Strange Data space wipe out with hashes
Thread Previous
|
Thread Next
From:
Uri Guttman
Date:
September 17, 2009 09:28
Subject:
Re: Strange Data space wipe out with hashes
Message ID:
87ocp9mt7v.fsf@quad.sysarch.com
>>>>> "JR" == Jerry Rocteur <perl@rocteur.cc> writes:
JR> my %sib_master_hoa = (
JR> XXXX => [ 'XXXX <type>' ] ,
JR> XXXX_ERSALL => [ 'XXXX <type>', 'ERS CRCODOSS <type>', 'ERS ENVDOSS <type>', 'ERS ENVVAL <type>' ],
JR> XXXX_ERSOTHERS => [ 'XXXX <type>', 'ERS CRCODOSS <type>', 'ERS ENVVAL <type>' ],
JR> );
this is a good place to show how to better format nested structures like
that. EVERYONE here should note this: :)
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>',
],
);
nested data should be indented and arrays listed in columns (unless they
are very short). note that each element ends in a comma as perl allows
it. it makes for easier cut/pasting of data lines so you don't have to
worry about which data ends in commas or not.
JR> sub AddGroup {
JR> my ($sib_user, $sib_profile, $sib_sibprofx) = @_;
JR> #
JR> for my $profile ( @{ $sib_master_hoa{$sib_profile} } ) {
$profile is aliased to each element of the list, not a copy.
JR> $profile =~ s/<type>/$sib_sibprofx/g;
so that line modifies the elements of the list in the original hash.
JR> print "-A $sib_user -g $profile\n";
JR> }
the solution is to either copy the list or the element.
my @profiles = @{ $sib_master_hoa{$sib_profile} } ;
for my $profile ( @profiles ) {
or
(my $new_prof = $profile ) =~ s/<type>/$sib_sibprofx/g;
and print $new_prof.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
Thread Previous
|
Thread Next