I'm trying to test for the presence of each key in the follwing hash which contains 'copy_[0-9]_frag_[0-9]_id. If found, I want to assign the value to $id%images { => copy_1_frag_1_id, => 12345 => copy_1_frag_2_id, => 67890 => key, => val => some_other_key => some_other_val }
Part two:
Elsewhere in the code I'm building a hash called %status. if $status{$client}{'tapes'}{$id} doesn't exist, then push it in.
Here's what I've got, so far:
Here's a snippet of the results of running the above code:#!/opt/openv/perl/bin/perl -w use strict; use NBUX; use Data::Dumper; my %images = bpimagelist(); my %status; my $id; foreach my $key (sort keys %images) { my $client = $images{$key}->{'client'}; my $sched_type = $images{$key}->{'schedule_type'}; my $sched_name = $images{$key}->{'sched_label'}; my $policy = $images{$key}->{'policy'}; my $kb = $images{$key}->{'kbytes'}; if (grep "copy\_[0-9]\_frag\_[0-9]\_id", $images{$key}) { $id = $images{$key}->{$_}; } if ( ! exists ( $status{$client}{'policy'}{$policy} )) { push @{$status{$client}{'policy'}} , $policy ; } if ( ! exists( $status{$client}{'tapes'}{$id} )) { push @{$status{$client}{'tapes'}} , $id ; } } print Dumper(\%status);
'dbsrv1' => { 'policy' => [ 'dbsrv1_misc_os', 'dbsrv1_misc_os', 'dbsrv1_misc_os', 'dbsrv1_misc_os', 'dbsrv1_dbps_hot', 'dbsrv1_dbps_hot', 'dbsrv1_dbps_hot', 'dbsrv1_arch', 'dbsrv1_arch', 'dbsrv1_os', 'dbsrv1_os', 'dbsrv1_os' ], 'tapes' => [ undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef ], },
In reply to Pattern-matching hash keys by blink
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |