Du bist hier: Snippet-Verzeichnis » Perl (198)
Sprache:

A simple perl-preprocessor

Sprache: English
Programmiersprache: Perl
Veröffentlicht von: iblech [nicht registriert]
Letzte Änderung: 15.05.2006
Aufrufe: 1134


Beschreibung

This perl script is a simple pre-processor for documents of any type. From STDIN it gives everything between '[+' and '+]' to the Perl interpreter, and pastes this (and the rest) to STDOUT. Useful for little dynamic websites.

Code

1 #!/usr/bin/perl -w 2 # myeperl - Prepocessor for documents, embedded Perl. 3 # Copyright (C) Don Aug 23 19:01:36 MEST 2001 by Ingo Blechschmidt 4 # 5 # This program is free software; you can redistribute it and/or modify 6 # it under the terms of the GNU General Public License as published by 7 # the Free Software Foundation; either version 2 of the License, or 8 # (at your option) any later version. 9 # 10 # This program is distributed in the hope that it will be useful, 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 # GNU General Public License for more details. 14 # 15 # You should have received a copy of the GNU General Public License 16 # along with this program; if not, write to the Free Software 17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 # 19 # Ingo Blechschmidt 20 # Arberstrae 5 21 # 86179 Augsburg 22 # E-Mail: iblech@web.de, http://www.way.to/uselinux/ 23 # Tel.: +49 / 821 882955 24 # 25 # 26 27 $mchar = ''; 28 $mstarte = 0; 29 $tchar = ''; 30 $tstring = ''; 31 32 while(not eof STDIN) { 33 $mchar = getc STDIN; 34 if ($mstarte == 2) { 35 $tchar = ''; 36 $tstring = ''; 37 while($tchar ne ']') { 38 $tchar = getc STDIN; 39 $tstring .= $tchar; 40 } 41 $tstring = substr($tstring, 0, length($tstring) - 2); 42 ##### 43 # system("perl -e '$tstring' > /tmp/myeperl.tmp"); 44 # open(EPERL, '</tmp/myeperl.tmp') || 45 # die 'Can\' t open /tmp/myeperl.tmp!'; 46 # print <EPERL>; 47 # close(EPERL); 48 ##### 49 { eval("$tstring"); } 50 ##### 51 $mstarte = 0; 52 $mchar = ']' 53 } 54 if ($mchar eq '[' or $mchar eq '+') { 55 $mstarte++; 56 } elsif ($mchar eq ']') { 57 # do nothing 58 } else { 59 print $mchar; 60 } 61 } 62

Noch kein Kommentar vorhanden

Dieses Snippet kommentieren

Name *  

E-Mail (wird nicht angezeigt) *    

Website  

Kommentar *  

Sicherheitscode Sicherheitscode *    

RSS