Eri Mendz wrote: > > hello everyone, Hello,
> since im learning perl, i might as well harness its power to solve my > small real-world problem. sample lines of my grep'ped ppp log goes > like this: > > Jan 12 05:47:50 localhost pppd[8696]: Connect time 2.2 minutes. > Jan 12 19:23:44 localhost pppd[9359]: Connect time 34.0 minutes. > [..] > Jan 17 14:12:06 localhost pppd[20127]: Connect time 12.6 minutes. > Jan 17 17:17:12 localhost pppd[20398]: Connect time 21.1 minutes. > [..] > Feb 3 17:59:42 localhost pppd[22888]: Connect time 4.4 minutes. > Feb 3 21:12:22 localhost pppd[23421]: Connect time 7.5 minutes. > ^^^^^ > i want to extract the time field on each line and get the sum total each > time i end my net session (sort of estimating my time online). have > started my perl script like this: > > #!/usr/bin/perl -w > use strict; > > while (<>){ > my $string = $_; > my @string = split /\s+/, $string; > print "$string[7]\n"; > } > exit; > > this just prints the time field on each line until finish of loop. i > tried using += operator to get sum but i end up getting errors. how do i > do this? i checked my script with perl's -c flag and it says syntax OK > but i get errors when i run the script in command line: Something like this should work: #!/usr/bin/perl -w use strict; my $total; while ( <> ) { next unless /Connect time ([\d.]+) minutes/; $total += $1 * 60; # convert to seconds } print 'Total minutes: ', $total / 60, "\n"; exit; John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]