Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (2)
As of 2024-04-20 03:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found