Ed X: Umfrage-Script gesucht

Beitrag lesen

hallo Sven,

also ich kann und will dir nicht die ganze Arbeit abnehmen. Ich hoffe du verstehst die Grundlagen von Perl. Dieses Script habe ich eigentlich für eine große Umfrage geschrieben. Es sendete nach jedem Eintrag die Daten an eine E-mailadresse mit einer *.csv datei von jedem datensatz im Anhang. Außerdem wurden die Daten in einer großen *.csv Datei auf dem Server gesammelt. Das ist wohl dann das was du brauchst.

<------------schnipp------------------>
#!f:/copyprog/perl56/bin/perl.exe -w

by Ed X

$filename = 'umfrage'; # name of the created file
$ext  = '.csv'; # extension(include the dot!!!!)
$TZ = 1; # serverzeitabweichung von Greewich

############################################################################

Retrieve Date

&get_date;

Parse Form Contents

&parse_form;

Erzeuge csv.file

&write_csv;

print "Location: http://(nach wo auch immer)\n\n";
#####################################################################

erhalten des Datums

sub get_date {
 # Define arrays for the day of the week and month of the year.  #
 my @days = ('Sun','Mon','Tue','Wed','Thu','Fri','Sat');
 my @months = ('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep',
    'Oct','Nov','Dec');
 # Get the current time and format the hour, minutes and seconds.  Add #
 # 1900 to the year to get the full 4 digit year.      #
 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$jday,$offs) = (localtime(time))[0,1,2,3,4,5,6,7,8];
 my $nowtime = sprintf("%02d:%02d:%02d",$hour,$min,$sec);
 $year += 1900;
 my $TimeZ += sprintf("%1d00",$offs+$TZ);
 # Format the date.              #
 $date = "$days[$wday], $mday $months[$mon] $year $nowtime +0$TimeZ";

}

parsen der daten

sub parse_form {
    local ($buffer, @pairs, $pair, $name, $value);
    $ENV{'REQUEST_METHOD'} =~ tr/a-z/A-Z/;
    if ($ENV{'REQUEST_METHOD'} eq "POST")
  {
  read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
  }
    else
  {
  $buffer = $ENV{'QUERY_STRING'};
  }
 @pairs = split(/&/, $buffer);
 foreach $pair (@pairs)
  {
  local($name, $value) = split(/=/, $pair);
  $value =~ tr/+/ /;
  $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
  # erases SSI, if included (from Matt Wright's FormMail)
  $value =~ s/<!--(.|\n)*-->//g;
  if ($Form{$name} && $value)
   {
   $Form{$name} = "$Form{$name},$value";
   }
  elsif ($value)
   {
   push(@Fields,$name);
   $Form{$name} = $value;
   }
  }
}

writes the datas into the db(*.csv)-file#

sub write_csv {
 if(-f $filename.$ext)
  {
  open(CSVFILE, ">>$filename$ext") || die "Fehler beim Oeffnen der Datei";
  foreach $field (@Fields)
   {
   if ($Form{$field})
    {
    print CSVFILE "$Form{$field};";
    }
   }
  print CSVFILE "\n";
  close(CSVFILE);
  }
 else
  {
  &new_file;
  }
}

creates a raw db-file including a header line

sub new_file {
 open(CSVFILE,">$filename$ext") || die "Fehler beim Erstellen der Datei";
 print CSVFILE "date;";
 foreach $field (@Fields)
  {
  if ($field)
   {
   print CSVFILE "$field;";
   }
 }
 print CSVFILE "\n";
 print CSVFILE "$date;";
 foreach $field (@Fields)
  {
  if ($Form{$field})
   {
   print CSVFILE "$Form{$field};";
   }
 }
 print CSVFILE "\n";
 close(CSVFILE);
}

<-------schnapp------------------>

ließ es dir durch und verstehe es(hoffe ich)
wiegesagt es sind nur die rudimantären funktionen.

Bye Ed X