in reply to Update hash value
Your two if statements are incompatible - they can never both be true, so no substitution can happen. Aside from that the code works. Consider:
use strict; use warnings; my $HR_wnt = {'res.ldlibrarypath' => 'Flobble=/opt/app/Flobble:'}; my $HR_unx; my $HR_component; my $target = 'Flobble'; for my $hashref ($HR_wnt, $HR_unx, $HR_component) { for my $id (keys %$hashref) { if ($id eq 'res.ldlibrarypath') { if ($$hashref{$id} =~ /=\//) { $$hashref{$id} =~ s/\/opt\/app\/$target.*?://; } } } } print $HR_wnt->{'res.ldlibrarypath'};
Prints:
Flobble=
Update actually there is nothing wrong with the two if statements. Bogus comment struck, working sample data supplied, commented code reinstated and sample output corrected.
|
|---|