On Jan 20, 2004, at 2:52 PM, Anthony J Segelhorst wrote:

James Edward Gray II <[EMAIL PROTECTED]>
01/20/2004 02:11 PM

I got this script written from James gave me:

Right here you left out:


use strict;
use warnings;

While not required, they're and important step in gaining Perl mastery. Start forming good habits now.

$servers = "/tmp/ep_report_db_test1.log";

my $servers = '/tmp/ep_report_db_test1.log'; # will get past strict


open (SERVERFILE, "<$servers");

Just out of curiosity, did you try my script? It handled opens for you, if called as documented and thus didn't need them to be hard coded.


If you want to handle you own opens though, you must make sure they succeed:

open SERVERFILE, $servers or die "File error: $!\n";

my($last, $counter) = (undef, 0);
while (<SERVERFILE>) {
                chomp;

if ($last) {
if ($_ eq $last) { $counter++; }
else {
print "$last,$counter\n";
undef $last;
$counter = 0;

I messed the above three lines up. My fault. Try these instead:


                                        print "$last,$counter\n";
                                        $last = $_;
                                        $counter = 1;

                                 }
                 }
                 else {
                                 $last = $_;
                                 $counter++;
                 }

I also left out an important line right here:


print "$last,$counter\n" if eof;

}


But now I am having problems counting if there is one record of that line?
Any suggestions?

See if the above fixes you up. Sorry about the mistakes.


James


-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to