This is really a two-part question. Part number one:
%images { => copy_1_frag_1_id, => 12345 => copy_1_frag_2_id, => 67890 => key, => val => some_other_key => some_other_val }
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

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:

#!/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);
Here's a snippet of the results of running the above code:
'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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.