CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Simple way???

 



Rivotti
User

Dec 17, 2000, 8:47 PM

Post #1 of 1 (257 views)
Simple way??? Can't Post

Hi,

I'm doing a script that open an html file, get param inside the html and them print them out separated by \n.

#The HTML file looks like:
# file.html

<html>
<head>
</head>
<body>
<form>
<p><font color="<FM_VAR COLOR=NOME>">Nome: <FM_VAR NAME=NOME,TEXTO,,50,*></font></p><p><font color="<FM_VAR COLOR=MORADA>">Morada: <FM_VAR NAME=MORADA,TEXTO_LONGO,Morada,50x4,*></font></p>
<p><font color="<FM_VAR COLOR=PASS>">Password: <FM_VAR NAME=PASS,PASS,,30,*></font></p>
<p><font color="<FM_VAR COLOR=PAIS>">Pais: <FM_VAR NAME=PAIS,LISTA_PAIS,Portugal,,*></font></p>
<p><font color="<FM_VAR COLOR=PAIS1>">Pais1: <FM_VAR NAME=PAIS1,LISTA_PAIS,Zimbabwe,,*></font></p>
<p><font color="<FM_VAR COLOR=CONCELHO>">Concelho: <FM_VAR NAME=CONCELHO,LISTA_CONCELHO,Sintra,distrito|DISTRITO,*></font></p><p><font color="<FM_VAR COLOR=DISTRITO>">Distrito: <FM_VAR NAME=DISTRITO,LISTA_DISTRITO,Lisboa,,*></font></p>
<p>Check Box 1: <FM_VAR NAME=CHECK1,CHECKBOX,OFF,,></p>
<p>Check Box 2: <FM_VAR NAME=CHECK2,CHECKBOX,ON,,></p>
<FM_VAR NAME=ESCONDIDO,HIDE,e-mail,,>
</form>
</body>
</html>

# The script file
# file.cgi

#!/usr/bin/perl

open(INFILE,"<file.html") || die;
@trash = <INFILE>;
close(INFILE);

$html = join("",@trash);
$html =~ s/<FM_VAR NAME=/\n<FM_VAR NAME=/g;
@html = split(/\n/,$html);

foreach(@html) {
chop $_;
if($_ =~ /<FM_VAR NAME=/) {
$_ =~ s/^<FM_VAR NAME=//g;
$_ =~ s/>(\W|\w)*<FM_VAR NAME=/\n/;
$_ =~ s/>(\W|\w)*$//g;
print "$_\n";
}
}

# The output result

NOME,TEXTO,,50,*
MORADA,TEXTO_LONGO,Morada,50x4,*
PASS,PASS,,30,*
PAIS,LISTA_PAIS,Portugal,,*
PAIS1,LISTA_PAIS,Zimbabwe,,*
CONCELHO,LISTA_CONCELHO,Sintra,distrito|DISTRITO,*
DISTRITO,LISTA_DISTRITO,Lisboa,,*
CHECK1,CHECKBOX,OFF,,
CHECK2,CHECKBOX,ON,,
ESCONDIDO,HIDE,e-mail,,

Now the question: is there a simple/better way to do this?

Thanks in advance
Rivotti


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives