A rewrite (yes, I've changed the coding style slightly...): (Be forewarned that this is very much untested.)

#!/usr/bin/perl -w use strict; my $home = $ENV{HOME} || (getpwuid($<))[7]; my $mail_to = 'me@employer'; # XXX when is this used? my $outfile = "$home/store_errors"; my $delivery_dir = "$home/delivery"; my $no_curropt_dir = "$home/no_curropt_stores"; my $error_pat = "$delivery_dir/error*"; my $no_error_pat = "$delivery_dir/no_error*"; my $corrupt_pat = "$no_curropt_dir/corrupt*"; my $no_corrupt_pat = "$no_curropt_dir/no_corrupt*"; my $store_list = "/store_list.full_listing"; my $date = scalar localtime; exit unless `netstat -i` =~ /^P01$/mi; sub store_name_map { map { (split /\./, $_, 2)[1] } @_ } sub uniques { my %seen; $seen{$_}++ for @_; return sort grep { $seen{$_} == 1 } keys %seen; } open STORES, "<$store_list" or die "opening $store_list for reading: $ +!\n"; my @stores = <STORES>; close STORES; my @errors = store_name_map(glob($error_pat)); my @no_errors = store_name_map(glob($no_error_pat)); my @error_union= uniques(@stores,@errors,@no_errors) my @corrupt = store_name_map(glob($curropt_pat)); my @no_curropt= store_name_map(glob($no_curropt_pat)); my @curropt_union= unqiues(@stores,@corrupt,@no_curropt); my $store_count = scalar(@stores); my $error_count = @errors + @no_errors; # - $store_count; my $curropt_count = @curropt + @no_curropt; # - $store_count; # XXX what were the - $NUM_STORES for? my $no_error_count = $store_count - $error_count; my $no_curropt_count = $store_count - $curropt_count; open OUTFILE, ">$outfile" or die "opening $outfile (for writing): $!\n +"; local $" = "\n\t\t"; # proper array output format print OUTFILE <<"END"; <snip> listing for $date Error Section There were a total of $store_count stores. \tThere were $error_count stores that reported in. \tThere were $no_error_count that did not report in. \t\t@error_union \tThere were $error_count that reported errors. \t\t@errors Curroption Section There were a total of $store_count stores. \tThere were $curropt_count stores that reported in. \tThere were $no_curropt_count stores that did not report in. \t\t@corrupt_union \tThere were $curropt_count that reported errors. \t\t@corrupt END

I guessed in a few places what you wanted to do.

This is probably a lot more wasteful then yours would be if it worked, due to not using temperorary files; that could probably be remidied with a bit of work. I hope that this helps you learn how to code better...


In reply to Re: Re: Re: Re: Problem with subroutine by wog
in thread Problem with subroutine by coec

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.