Neuigkeiten:

still alive...

Hauptmenü

perl 2 php

Begonnen von moxquiz, 27. Januar 2007, 16:32:25

Vorheriges Thema - Nächstes Thema

moxquiz

Hi,
ich hab mal ne frage. /uploads/emoticons/icon_e_wink.gif.fcb053ab2c91cb6224c03a16c6332abf.gif\" alt=\";)\" />
Wäre es theoretisch(!) möglich folgendes perl-script als php script umzuschreiben. Das wertet zZt ne Datei aus, die ich direkt dadrunter poste.
 

#!/usr/bin/perl
##
### allstars.pl -- prettyprint the allstars table for MoxQuizz
##
### Author: Moxon   (AKA Sascha Lüdecke)
##
### Copyright (C) 2000 Moxon AKA Sascha Lüdecke
##
##  This program is free software; you can redistribute it and/or modify
##  it under the terms of the GNU General Public License as published by
##  the Free Software Foundation; either version 2 of the License, or
##  (at your option) any later version.
##
##  This program is distributed in the hope that it will be useful,
##  but WITHOUT ANY WARRANTY; without even the implied warranty of
##  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
##  GNU General Public License for more details.
##
##  You should have received a copy of the GNU General Public License
##  along with this program; if not, write to the Free Software
##  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
##
###
#  $Id: allstars.pl,v 1.12 2002/02/22 10:20:34 chat Exp $
my $allstarsfile = \\\'rankallstars.data\\\';
my $format = \\\"TXT\\\";
my $monthly = 0;
my $currentmonthonly = 0;
my $monthlybase = \\\'allstars\\\';
while ($_ = shift @ARGV) {
   # options first
   /--file/ && do { $allstarsfile = shift @ARGV;
     print STDERR \\\"Reading from $allstarsfile\\\\n\\\";
     next };
   /--html/ && do { $format = \\\"HTML\\\";
     next };
   /--xml/ && do { $format = \\\"XML\\\";
    next };
   /--text/ && do { $format = \\\"TXT\\\";
     next };
   /--monthly-prefix/ && do { $prefix = shift @ARGV;
          $monthlybase = $prefix . \\\".\\\" . $monthlybase;
          next };
   /--monthly/ && do { $monthly = 1;
   next };
   /--current-month-only/ && do { $currentmonthonly = 1;
                                  next };
   # commands last
   /--list/ && do {  list_entries();
      exit 0 };
   /--table/ && do { calc_table();
      exit 0 };
   /--help/ && do { print_help();
     exit 0 };
   print STDERR \\\"Unknown parameter: \\\\\\\"$_\\\\\\\"\\\\n\\\";
}
print STDERR \\\"No command found, use --help to get help.\\\\n\\\";
exit 1;
 
###########################################################################
#
# list all entries
#
###########################################################################
## SAMPLE
##  
##   # this file records all won games.  Format is:
##   # time,  duration, num of questions, winscore, nick, hostmask
##   964263720 371 : 41 15 -- MindMaster *!whistle@*.blowup.net
##  
sub list_entries () {
   if (open FILE, \\\"$allstarsfile\\\") {
while () {
    chomp;
    # skip comments
    if ($_ !~ /^\\\\#.*/) {
$_ =~ /(\\\\d+) (\\\\d+) : (\\\\d+) (\\\\d+) -- ([^ ]+) ([^ ]+)/;
print localtime($1) . \\\" $1  $2\\\\t$3\\\\t$4  $5  $6\\\\n\\\";
    }
}
close FILE;
   } else {
die \\\"Could not open $allstarsfile.\\\";
   }
}
 
###########################################################################
#
# calculate table(s in case of monthly tables)
#
###########################################################################
sub calc_table () {
   local %games, %score, %durations;
   local $lastmonth = \\\"\\\";
   $| = 1;
   # read the file
   if (open FILE, \\\"$allstarsfile\\\") {
while () {
    chomp;
    if ($_ !~ /^\\\\#.*/ && $_ !~ /^\\\\s*$/ ) {
$_ =~ /(\\\\d+) (\\\\d+) : (\\\\d+) (\\\\d+) -- ([^ ]+) ([^ ]+)/;
($when, $duration, $sumscore, $score, $name, $host) = ($1, $2, $3, $4, $5, $6);
if ($lastmonth eq \\\"\\\") {
    $lastmonth = getYearMonth($when);
}
if ($monthly && getYearMonth($when) ne $lastmonth) {
                   if (!$currentmonthonly) {
                       print_table();
                   } else {
                       print STDERR \\\"Skipping $lastmonth.\\\\n\\\"
                   }
    $lastmonth = getYearMonth($when);
    undef %games;
    undef %durations;
    undef %score;
}
$games{$name} += 1;
$durations{$name} += $duration;
$score{$name} += 10 * $sumscore / ( log10($score) * $duration );
    }
}
close FILE;
print_table();
   } else {
die \\\"Could not open $allstarsfile.\\\";
   }
}
###########################################################################
#
# print a table -- assumes %games, %score and %duration to be filled
#
###########################################################################
sub print_table () {
   if ($monthly) {
print STDERR \\\"Writing month: $monthlybase.$lastmonth\\\\n\\\";
open (STDOUT,  \\\">$monthlybase.$lastmonth\\\");
   }
   # set page length so show everything on a single page
   $= = 1_000_000;
   $- = 0;
   # set format
   $^ = $format . \\\"HEAD\\\";
   $~ = $format . \\\"BODY\\\";
   # show the table
   $pos = 1;
   foreach $n (sort {$score{$b}  $score{$a}} keys %games) {
write;
$pos += 1;
$games{\\\"Summary\\\"} += $games{$n};
$durations{\\\"Summary\\\"} += $durations{$n};
$score{\\\"Summary\\\"} += $score{$n};
   }
   # show some summaries
   $~ = $format . \\\"SUMS\\\";
   $pos = \\\"\\\";
   $n = \\\"Summary\\\";
   write;
 
   # print footer
   $~ = $format . \\\"FOOT\\\";
   write;
   if ($monthly) {
close (STDOUT);
   }
}
###########################################################################
#
# print a help text
#
###########################################################################
sub print_help () {
   print   Use  instead of \\\\\\\'$allstarsfile\\\\\\\' for input.
--monthly   Calculate allstars per month and write to files like
            $monthlybase.2001-01
--monthly-prefix
                   Prepend  to above filenames
    Output formats in case of --table:
--html      Generated HTML output
--xml       Generate XML output
--text      Generate Text output (this is the default)
Example:
   allstars.pl --file rankallstars --monthly --monthly-prefix en --xml --table
   Generates XML allstars table from file \\\'rankallstars\\\' on a monthly base
   into files named alike en.$monthlybase.2001-01
HELP
}
 
###########################################################################
#
# help routines like log10 and getMonth
#
###########################################################################
sub log10 ($) {
   my $n = shift;
   return log($n)/log(10);
}
 
sub getYearMonth($) {
   my $secs = shift;
   ($_, $_, $_, $_, $month, $year, $_, $_, $_) = localtime $secs;
   return sprintf(\\\"%d-%02d\\\", 1900 + $year, $month + 1);
}
###########################################################################
#
# output formats
#
# To get a new format, give it a tag (e.g. XML) and write formats named
# HEAD, BODY, SUMS, FOOT
#
###########################################################################
###########################################################################
# TXT
###########################################################################
format TXTHEAD =
Allstars table
--------------
Rank |       Name       | Games |   Score | Avg score | Avg duration
-----+------------------+-------+---------+-----------+-------------
.
 
format TXTBODY =
@>>> | @>> | @
Rank  Name Games
  Score  Avg score   Avg duration 
.
format HTMLBODY =
@>>>   @ @####   @###.###   @###.### @###.###
$pos, $n, $games{$n}, $score{$n}, $score{$n}/$games{$n},  $durations{$n}/$games{$n}
.
format HTMLSUMS =
@>>>   @ @###   @###.###   @###.### @###.###
$pos, $n, $games{$n}, $score{$n}, $score{$n}/$games{$n},  $durations{$n}/$games{$n}
.
 
format HTMLFOOT =
 
This table was created on @.
\\\"\\\" . localtime(time)
.
 
###########################################################################
# XML
###########################################################################
format XMLHEAD =
 
.
format XMLBODY =
   @>>>>
$pos
   @
$n
   @#####
$games{$n}
   @###.###
$score{$n}
   @###.###
$score{$n}/$games{$n}
   @###.###
$durations{$n}/$games{$n}
.
format XMLSUMS =
   @>>>>
$pos
   @
$n
   @#####
$games{$n}
   @###.####
$score{$n}
   @###.####
$score{$n}/$games{$n}
   @###.####
$durations{$n}/$games{$n}
.
format XMLFOOT =
@>>>>>>>>>>>>>>>>>>>>>>>>>>>
\\\"\\\" . localtime(time)
.
 

 
 
 
Hier die auszuwertende Datei:
 

1159829124 1234 : 37 30 -- [bTK]THS *!*thsherb@*.dip0.t-ipconnect.de
1159956565 905 : 33 30 -- JavaUser0 *!*JavaUser@*.t-dialin.net
1159958024 1333 : 47 30 -- Blaczek *!Blaczek89@*.arcor-ip.net
1159976113 1483 : 60 31 -- Blaczek *!Blaczek89@*.arcor-ip.net
1159982710 395 : 32 31 -- Tarantino` *!*rantino@*.t.pppool.de
1159988491 473 : 31 30 -- EntropyFan *!*tescht@*.user.gamesurge
1160071368 319 : 51 30 -- Aktien_Index_DAX *!*none@*.aol.com
1160162836 792 : 31 30 -- kaffee *!*tescht@*.user.gamesurge
1160224792 430 : 39 30 -- |-typ-| *!*tescht@*.user.gamesurge
1160237024 2674 : 83 30 -- [smEP]Disco-Stu *!*jensdaub@*.t.pppool.de
1160238801 1115 : 66 30 -- nawI|afk *!*Iwan@*.user.gamesurge
1160241796 1257 : 72 30 -- nawI|afk *!*Iwan@*.user.gamesurge
1160243316 1489 : 54 30 -- pluto`planet`der`herzen *!*tescht@*.user.gamesurge
1160246673 2547 : 73 30 -- Malak_al-haq *!*0winger@213.254.54.*
1160248271 1477 : 48 30 -- apfelfred *!*appstuh@*.t-dialin.net
1160250165 378 : 31 30 -- Tarantino` *!*Quiz.de@*.t.pppool.de
1160264045 1814 : 56 30 -- [smEP]Disco-Stu^Shisha_rauchen *!*jensdaub@*.t.pppool.de
1160306067 2107 : 57 31 -- Soul_Reaper *!blubb@*.adsl.hansenet.de
1160310401 1582 : 54 30 -- nawI|afk *!*Iwan@*.user.gamesurge
1160312001 1467 : 57 30 -- nawI|afk *!*Iwan@*.user.gamesurge
1160313994 1910 : 79 30 -- nawI|afk *!*Iwan@*.user.gamesurge
1160319668 1407 : 56 30 -- Belle *!*Quagga@*.t-dialin.net
1160321904 2001 : 80 30 -- nawI|afk *!*Iwan@*.user.gamesurge
1160326796 813 : 43 30 -- beugung *!*kwizzer@88.207.255.*
1160336993 2640 : 102 30 -- fjdksahf *!*quizzzz@*.user.gamesurge
1160338713 1557 : 60 30 -- dfksjfla *!*quizzzz@*.user.gamesurge
1160342000 1741 : 93 30 -- kabo_Om *!*kaboom@83.228.157.*
1160343401 1345 : 49 30 -- IlseJaund *!*seJaund@*.t-dialin.net
1160345976 802 : 32 30 -- Rosenstolz *!*xyz@*.dip0.t-ipconnect.de
1160384434 1049 : 56 30 -- Rosenstolz *!*xyz@*.dip0.t-ipconnect.de
1160385210 741 : 33 32 -- pluto *!*quizzzz@*.user.gamesurge
1160389344 1085 : 33 30 -- nawI|afk *!*Iwan@*.user.gamesurge
1160391390 1129 : 48 32 -- dksajl *!*quizzzz@*.user.gamesurge
1160394526 1722 : 67 30 -- nawI|afk *!*Iwan@*.user.gamesurge
1160414655 982 : 49 30 -- pluto *!*quizzzz@*.user.gamesurge
1160415862 1039 : 49 30 -- falschen`vornamen`mitquizzer *!*quizzzz@*.user.gamesurge
1160418372 1164 : 32 31 -- kabo_Om *!*kaboom@83.228.223.*
1160427978 1019 : 48 30 -- Reincarnation *!*incarna@*.cyber-criminal.gamesurge
1160492269 550 : 45 31 -- Zimratam *!*izzer98@88.207.255.*
1160495013 1021 : 41 30 -- Reincarnation *!*incarna@*.cyber-criminal.gamesurge
1160496246 1162 : 32 30 -- Sharky| *!*PE_Shar@*.user.gamesurge
1160499063 366 : 44 30 -- Tarantino` *!*Quiz.de@*.t.pppool.de
1160500213 851 : 39 30 -- Sharky| *!*PE_Shar@*.user.gamesurge
1160502259 739 : 76 33 -- Heartbreaker *!*Blacky@*.t-dialin.net
1160506675 1344 : 77 30 -- nawI|afk *!*Iwan@*.user.gamesurge
1160508949 2244 : 73 30 -- Sharky| *!*PE_Shar@*.user.gamesurge
1160509839 756 : 48 30 -- tele`tuebbi *!*quizzzz@*.user.gamesurge
1160510981 995 : 58 30 -- Lifeforce *!*feforce@*.t.pppool.de
1160512087 1019 : 49 30 -- Reincarnation *!*incarna@*.cyber-criminal.gamesurge
1160514433 2216 : 76 30 -- Sharky| *!*PE_Shar@*.user.gamesurge
1160524192 356 : 57 30 -- Aktien_Index_DAX *!QuizCHat@*.user.gamesurge
1160527033 1267 : 31 30 -- Blaczek *!*aczek89@*.arcor-ip.net
1160528583 1499 : 31 30 -- Lonesome^Quizzer *!*aczek89@*.arcor-ip.net
1160532647 1396 : 36 30 -- Blaczek *!*aczek89@*.arcor-ip.net
1160575477 737 : 38 31 -- tescht *!*quizzzz@*.t-dialin.net
1160577064 484 : 31 30 -- |-test-| *!*quizzzz@*.t-dialin.net
1160578545 580 : 55 31 -- Zimratam *!*kwizzer@88.207.255.*
1160581218 511 : 31 30 -- Reincarnation *!*incarna@*.dip0.t-ipconnect.de
1160582367 998 : 43 30 -- |-heul-| *!*izzzzzz@*.user.gamesurge
1160583417 323 : 31 30 -- Topictester *!Asia@*.user.gamesurge
1160584273 650 : 35 30 -- |-afk-| *!*izzzzzz@*.user.gamesurge
1160585310 694 : 39 33 -- Reincarnation *!*incarna@*.dip0.t-ipconnect.de
1160587326 680 : 31 30 -- fdasfjk *!*izzzzzz@*.t-dialin.net
1160588199 509 : 31 30 -- |-typ-| *!*izzzzzz@*.t-dialin.net
1160597815 985 : 44 30 -- kabo_Om *!*kaboom@83.228.165.*
1160599442 586 : 36 34 -- |-tescht-| *!*izzzzzz@*.beta-tester.gamesurge
1160645161 755 : 33 30 -- nawI|afk *!*Iwan@*.user.gamesurge
1160646120 873 : 41 30 -- tuebbi` *!*izzzzzz@*.t-dialin.net
1160653872 798 : 50 30 -- sofix *!*actical@*.games-naked.gamesurge
1160660018 1276 : 50 30 -- |-typ-| *!*izzzzzz@*.beta-tester.gamesurge
1160660560 434 : 32 30 -- uschi *!*izzmach@88.207.255.*
1160662494 1769 : 41 30 -- Sharky| *!*PE_Shar@*.user.gamesurge
1160664022 1495 : 35 30 -- Sharky| *!*PE_Shar@*.user.gamesurge
1160665344 1055 : 43 30 -- sofix *!*actical@*.games-naked.gamesurge
1160666918 476 : 51 31 -- Tuxi *!Asia@*.aol.com
1160671471 1817 : 35 30 -- Sharky| *!*PE_Shar@*.user.gamesurge
1160673695 1502 : 59 30 -- apfelfred *!*appstuh@*.t-dialin.net
1160676332 1302 : 35 30 -- Sharky| *!*PE_Shar@*.user.gamesurge
1160678399 1990 : 45 30 -- Sharky| *!*PE_Shar@*.user.gamesurge
1160679859 1305 : 54 30 -- quizzer *!*quizzer@*.arcor-ip.net
1160681150 553 : 58 32 -- gucki *!guck@*.t-dialin.net
1160684028 1021 : 72 30 -- Coldi *!wirc@217.151.115.*
1160685272 1032 : 54 33 -- Coldi *!wirc@217.151.115.*
1160733358 495 : 45 30 -- gucki *!guck@*.t-dialin.net
1160733943 354 : 33 30 -- gucki *!guck@*.t-dialin.net
1160739228 1701 : 65 30 -- nawI|afk *!*Iwan@*.user.gamesurge
1160739874 601 : 34 31 -- `pluto` *!*izzzzzz@*.beta-tester.gamesurge
1160748126 626 : 72 30 -- gucki *!guck@*.t-dialin.net
1160748584 344 : 33 30 -- gucki *!guck@*.t-dialin.net
1160756042 532 : 51 30 -- Aktien_Index_DAX *!Asia@*.user.gamesurge
1160757367 614 : 38 30 -- |Blizz| *!*Blizz@*.mediaWays.net
1160759140 1693 : 42 30 -- apfelfred *!*appstuh@*.t-dialin.net
1160761950 1817 : 72 30 -- Sharky| *!*PE_Shar@*.user.gamesurge
1160763290 913 : 53 30 -- Tarantino` *!*Quiz.de@*.t.pppool.de
1160767694 799 : 54 30 -- |Blizz| *!*Blizz@*.mediaWays.net
1160769167 690 : 66 30 -- Aktien_Index_DAX *!QuizCHat@*.user.gamesurge
1160770510 1291 : 56 30 -- Benny *!*Quiz.de@*.t.pppool.de
1160776862 679 : 37 30 -- `pluto` *!*izzzzzz@*.beta-tester.gamesurge
1160778157 896 : 34 30 -- nawI|afk *!*Iwan@*.user.gamesurge
1160815920 1713 : 50 30 -- apfelfred *!*felfred@*.t-dialin.net
1160817213 1176 : 49 30 -- Sharky| *!*PE_Shar@*.user.gamesurge
1160818455 1214 : 41 33 -- apfelfred *!*felfred@*.t-dialin.net
1160822017 771 : 35 31 -- Belle *!*Quagga@*.t-dialin.net
1160823950 490 : 60 30 -- AmoTe *!*max_kohm@*.t-dialin.net
1160826076 537 : 85 30 -- |-typ-| *!*izzzzzz@*.beta-tester.gamesurge
1160830851 945 : 58 30 -- gucki *!guck@*.t-dialin.net
1160831751 755 : 57 30 -- gucki *!guck@*.t-dialin.net
1160836956 478 : 37 30 -- Aktien_Index_DAX *!QuizCHat@*.user.gamesurge
1160837765 684 : 46 30 -- gucki *!guck@*.t-dialin.net
1160839348 1220 : 51 30 -- _Coldi_ *!wirc@217.151.116.*
1160840810 1347 : 45 33 -- Blaczek *!Blaczek89@*.arcor-ip.net
1160842033 1178 : 40 30 -- Belle *!*Quagga@*.t-dialin.net
1160843459 681 : 78 30 -- gucki *!guck@*.t-dialin.net
1160852816 1173 : 46 30 -- Belle *!*Quagga@*.t-dialin.net
1160854249 403 : 69 31 -- gucki *!guck@*.t-dialin.net
1160856614 1772 : 79 30 -- HagbarD *!wunDe@*.t-dialin.net
1160858546 1783 : 68 30 -- Charlie1973`is`24`7 *!*rlie197@*.adsl.alicedsl.de
1160859867 369 : 70 30 -- gucki *!guck@*.t-dialin.net
1160863092 2335 : 101 30 -- HagbarD *!wunDe@*.t-dialin.net
1160865618 1249 : 68 30 -- Tarantino *!*Quiz.de@*.t.pppool.de
1160866433 776 : 59 30 -- gucki *!guck@*.t-dialin.net
1160870780 342 : 45 30 -- gucki *!guck@*.t-dialin.net
1160879336 1749 : 41 30 -- AnnyMuenchhausen *!*Quiz.de@*.t.pppool.de
1160908747 551 : 85 30 -- gucki *!guck@*.t-dialin.net
1160915144 2606 : 84 30 -- HagbarD *!wunDe@*.t-dialin.net
1160917406 2230 : 83 30 -- JeDermaNN *!wunDe@*.t-dialin.net
1160919960 1200 : 88 30 -- sofix *!*actical@*.games-naked.gamesurge
1160922248 419 : 61 31 -- gucki *!guck@*.t-dialin.net
1160929439 397 : 32 30 -- |Blizz| *!*Blizz@*.mediaWays.net
1160930000 521 : 39 30 -- |Blizz| *!*Blizz@*.mediaWays.net
1160935223 1333 : 112 30 -- _Coldi_ *!wirc@217.151.115.*
1160935674 420 : 33 31 -- |Blizz| *!*Blizz@*.mediaWays.net
1160938246 428 : 54 30 -- |Blizz| *!*Blizz@*.mediaWays.net
1160939567 332 : 62 30 -- |Blizz| *!*Blizz@*.mediaWays.net
1160942477 2522 : 86 30 -- UnC3l_-Cr4ka *!*uz1_fuz1@*.dip0.t-ipconnect.de
1160945444 2892 : 108 30 -- Einherier *!Flavius@*.t-dialin.net
1160948045 2515 : 78 30 -- Goldauge *!*A-HC_Tu@*.t-dialin.net
1160949505 1399 : 39 30 -- Goldauge *!*A-HC_Tu@*.t-dialin.net
1160952126 2415 : 52 30 -- Iversen *!*s.ebbert@*.t-dialin.net
1160954543 1845 : 55 30 -- Dragsa|afk *!*TheHiob@*.arcor-ip.net
1160956609 1942 : 46 30 -- Dragsa|afk *!*TheHiob@*.arcor-ip.net
1160958467 1754 : 45 30 -- Dragsa|afk *!*TheHiob@*.arcor-ip.net
1160960814 2151 : 52 30 -- Dragsa|afk *!*TheHiob@*.arcor-ip.net
1160963567 2644 : 64 30 -- Dragsa|afk *!*TheHiob@*.arcor-ip.net

 
 
MfG,
moxquiz

raiser

da ich in perl nicht gans so fit bin, kann ich zwar nicht alles erkennen, was das script macht.
aber es sollte zu 100% möglich sein, das was dort steht auf php umzusetzen.

Wissen ist das einzige Gut, dass sich vermehrt, wenn man es teilt! (Marie von Ebner-Eschenbach)




Irren ist menschlich!




Wer andern eine Grube gräbt,


sollte darüber nachdenken,


ob sie tief genug ist!!!!




Kameradschaft ist, wenn der


Kamerad schafft !!!!


moxquiz


all your base are belong to us / Discord