Very frustrated with what I believe is a simple loop. Working Loop: lacts - passed in hash with status of backups + if status is /Completed$/ then skip lyester - passed in date to compare to backup date + if backup date older than lyester then skip
sub check_activity { # check activity - Exceptions, Failures, Active, Queued, Repli +cation ## defaults ## my $lresults = {}; my $WEEK = time - (7 * 24) * 3600; # time a week ago... ## passed ## my $lacts = shift; my $lyester = shift; my $act; print "here in check activity\n"; #print "keys - " . join(',', keys %{$lacts}) . "\n"; foreach $act ( keys %{$lacts} ) { print "$act - $lacts->{$act}->{Status} - $lacts->{$act +}->{Type} - $lacts->{$act}->{StartTime} - $lyester\n"; } return $lresults; } OUTPUT: here in check activity cut....cut 9132184440017109 - Completed w/Exception(s) - Scheduled Backup - 2011- +11-20 19:00 PST - 2011-11-22 14:54:12 9132192720051109 - Completed - Scheduled Backup - 2011-11-21 18:17 PST + - 2011-11-22 14:54:12 9132201360045609 - Completed - Scheduled Backup - 2011-11-22 18:05 PST + - 2011-11-22 14:54:12 1321898408398257 - Completed - Replication Source - 2011-11-21 10:00 P +ST - 2011-11-22 14:54:12 9132192720002809 - Timed Out - Start - Scheduled Backup - 2011-11-21 1 +8:00 PST - 2011-11-22 14:54:12 cut...cut
The loop works, however the checks have not been added. If I add a next if, or if statement it will make a single loop and exit the sub. Broken code - only performs single loop.
sub check_activity { # check activity - Exceptions, Failures, Active, Queued, Replicati +on ## defaults ## my $lresults = {}; my $WEEK = time - ( 7 * 24 ) * 3600; # time a week ago... ## passed ## my $lacts = shift; my $lyester = shift; my $act; print "here in check activity\n"; #print "keys - " . join(',', keys %{$lacts}) . "\n"; foreach $act ( keys %{$lacts} ) { print $act . " - " . $lacts->{$act}->{Status} . "\n"; next if $lacts->{$act}->{Status} =~ /Completed$/; print "$act - $lacts->{$act}->{Status} - $lacts->{$act +}->{Type} - $lacts->{$act}->{StartTime} - $lyester\n"; } return $lresults; } OUTPUT: here in check activity 9132201720006509 - Completed
Any thoughts or advice is greatly appreciated. - Chuck

In reply to Adding "if" statement to foreach causes only 1 run by TheChuckMo

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.