I have the following structure:
my @fields = (
{
"dbId" => "BabysSex",
"db2Id" => "DetSex",
"name" => "Baby's Sex",
"datatype" => "Text",
"outputorder" => 5,
"value" => undef,
},
{
"dbId" => "HospitalCode",
"name" => "Hospital Code",
"datatype" => "Text",
"value" => undef,
},
{
"dbId" => "UniqueIdenifier",
"name" => "Unique Identifier",
"datatype" => "Text",
"outputorder" => 7,
"value" => undef,
},
);
After assigning the values to each $filed[$i]->{"value"}, I need to do some further processing and expansion. For instance, the data set I am processing uses digits to represent different values for sex (eg 1 for male, 2 for female and so on). I can expand this in a for loop:
for ( my $i = 0 ; $i < scalar @fields ; $i++ ) {
if ( $fields[$i]->{"name"} =~ /sex/i && $fields[$i]->{"value"} )
{
$fields[$i]->{"value"} = $SexMap{ $fields[$i]->{"value"}};
}
}
What I would like to know is if I can use map to get the same results.
Thanks
for my $i (0..$#fields) {...}— read: foreach value$iin the range from 0 to the highest index in@fields. @hobbs solution is even cleaner.mapis used best for "piping" list to another command, I feel: print join "-", map {$_?'ZERO'} (0..5);` not for complex in-place edits