ziggy on Thu, 13 Apr 2000 19:01:41 -0400 (EDT)


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Perl Ripping Event (fwd)


Forwarded message:
> To: phl@lists.pm.org
> cc: mjd@plover.com
> Subject: Perl Ripping Event
> Organization: Plover Systems
> Date: Thu, 13 Apr 2000 18:31:05 -0400
> From: Mark-Jason Dominus <mjd@plover.com>
> 
> 
> The program below is supposed to read an `xferlog' file that contains
> records like these:
> 
> Mon Apr  5 19:59:17 1999 0 localhost 29433 /site/Uploads/install.log b _ i r glftpd ftp 1 root
> Mon Apr  5 19:59:17 1999 0 localhost 29433 /site/Uploads/install.log b _ i r carrot ftp 1 root
> 
> 
> and print a report.  This is real code; someone on IRC sent it to me
> and wanted to know how to get it to sort the output report by one of
> the fields.
> 
> I found a lot of stuff to say about it.
> 
> 
> #!/usr/bin/perl
> use Getopt::Std;
> getopt('dV');
> $xferlog="./xferlog";
> $\ = "\n";
> $i=0;
> open XFERLOG, $xferlog or die "Cant't find file $xferlog";
> 
> foreach $line (<XFERLOG>) {
>       chomp($line);
>       if (( $line =~ /$opt_d/i) && ( $line !~ /_ o r/)) 
>          {
>          ($Fld1,$Fld2,$Fld3,$Fld4,$Fld5,$Fld6,$Fld7,$Fld8,$Fld9,$Fld10,$Fld11,$Fld12,$Fld13,$Fld14,$Fld15) = split(' ',$line);
>           $uplist[$i] = join ' ',$Fld6, $Fld8, $Fld9, $Fld14, $Fld15;
> 	  $time[$i]=$Fld6; $size[$i]=$Fld8; $file[$i]=$Fld9; $user[$i]=$Fld14; $group[$i]=$Fld15;
>           $username= join '@', $user[$i], $group[$i];
>           push @{$table{$username}}, $uplist[$i];
> 	  $i++;     
>     }
> }
> close XFERLOG;
> 
> undef %saw;
> # @newuser = grep(!$saw{$_}++, @user);
> $j=0;
> foreach  $username ( sort keys %table )
>         {
> 	my @mylist = @{$table{$username}};
> 	$m=0;
>         $totalsize=0;
>         $totaltime=0;
> 	$gtotal=0;
>         $x=0;
>         $x=@mylist;
>         for ($m = 0 ; $m < ($x); $m++)
>         {
>                 ( $seconds, $size, $file, $user, $group) = split(' ', $mylist[$m]);
> 		$totaltime = ($totaltime + $seconds);
>                 $totalsize = ($totalsize + $size);
>         }
>         if ($totaltime==0) { $totaltime=1; }
>         if ($totalsize==0) { $totalsize=1; }
>         $avgtr = (($totalsize/$totaltime)/1024);
> 	$gtotal=($totalsize+$gtotal);
>         $finale[$j]= join ' ', ($totalsize/(1024*1024)), $username, ($x), $totaltime, $avgtr;
> #	print $finale[$j];
> 	$j++;
> }
> @realfinal =  sort @finale;
> #print @finale;
> $p=0;
> $w=0;
> $w=@realfinal;
> #print $w;
> for ($p=($w-1) ; $p>=0; $p--)
> {
>         ($Size, $User, $Files, $Time, $AvgSpeed)= split " ", $realfinal[$p];
>         $position= ($w-$p);
>         $percent=(($Size/($gtotal/(1024*1024)))*100);
>         printf ("$position. $User $Files files ");
>         printf("%.2fMB", $Size) ;
>         printf " $Time(s) ";
>         printf ("%.2f% ", $percent);
>         printf("%.2fK/s", $AvgSpeed);
>         print " ";
> }
> 
> 
> 

**Majordomo list services provided by PANIX <URL:http://www.panix.com>**
**To Unsubscribe, send "unsubscribe phl" to majordomo@lists.pm.org**