From: "Yacketta, Ronald" <[EMAIL PROTECTED]>
> I am sure someone out their in Perl land can offer a better solution
> to the following.
>
> ###
> ### slurp in all the required data for the report
> ###
> open ($LOG,"cat $g_logdir/OrderServer-*.log|")
> or die ( "Unable to open $g_logdir/OrderServer-*.log :
> $!");
Why don't you open the file directly?
open ($LOG,"$g_logdir/OrderServer-*.log")
or die ( "Unable to open $g_logdir/OrderServer-*.log : $!");
or am I misunderstanding something?
And to slurp the whole file to a scalar you can do this:
my $data = do {local $/; <$LOG>};
The
local $/;
turns on slurping (or turns off line reading, it's the same thing)
inside the block. The
do {}
just provides the block to localize the change of $/ and returns the
value of the last command in the block.
> as well as this
>
> ###
> ### Capture specific errors
> ###
> ...
I can't say anything about this without more information.
>
> ###
> ### Count number of successful order submits
> ###
> if ( $_ =~ /^<$g_date.*Units <(.*)> Submitted
> successfully/) {
> $Units{$1}++;
> $success++;
> $totalUnits += $1;
> $above4++ if ( $1 > 4 );
> }
How much does the $g_date change? If it gets set to something before
this regular expression is first evaluated you may want to add the /o
modifier:
if ( $_ =~ /^<$g_date.*Units <(.*)> Submitted successfully/o) {
It will instruct Perl to reuse the compiled regular expression
instead of recompiling it each time you evaluate this condition.
This could speed up the process considerably.
If the $g_date does change, but considerably less often than is this
condition evaluated you may want to read on qr// in the perlop
manpage and then use something like:
while (something) {
$g_date = ...;
$regexp = qr/^<$g_date.*Units <(.*)> Submitted successfully/;
...
while (something else) {
...
if ($_ =~ $regexp) {
...
}
}
...
}
That is you prepare the regexp and then reuse it several times.
HTH, Jenda
P.S.: It's silly to fret over someone perusing the information
acquired here in his job (to get a bussiness advantage). That's what
we are all here for (well almost). Besides, noone is forced to give
more than he/she wants to.
===== [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]