Link to home
Start Free TrialLog in
Avatar of malkie
malkie

asked on

Read and write file (part 2)

Further on with Read and write file.
-------
#!/usr/bin/perl

open I,"<info.txt" or die "Can't open info.txt $!";
open E,">enter.tab" or die "Can't open enter.tab $!";
$/="-------------\n";
while( <I> ){
   chomp;
   @l=split/\n/;
   @l = grep !/<input\s+type=(submit|reset)\b/i,@l;
   @i{"text","hidden"}=();
   for( @l ){
       if( /<input\s+type\s*=\s*(\S*).*\bname\s*=\s*(["']([^"']*)["']|(\S*)).*?\b(value\s*=\s*(["']([^"']*)["']|(\S*))).*>/
       ){
            $i{lc $1} .= "$3$4=$7$8,";
       }elsif( /<input\s+type\s*=\s*(\S*).*\bname\s*=\s*("([^"]*)"|(\S*)).*>/
       ){
            $i{lc $1} .= "$3$4=$3$4,";
       }
   }
   chop @i{"text","hidden"};
   #print E join("\t",$l[0],"General",$l[2],$l[1],"http://yes/image.gif",@l[3,4],@i{"text","hidden"},"0"),"\n";
   print E join("\t",$l[0],"General",$l[2],$l[1],"http://yes/image.gif",@l[3,4],@i{"text","hidden"},"Thank You","0"),"\n";
   
}

----------
The script needs to write the first line to enter.tab to set field names as:-
Code"\t"Category"\t"Description"\t"HomeUrl"\t"LogoUrl"\t"SubmitUrl"\t"Method"\t"Varmap"\t"StaticVars"\t"Success"\t"Default

The script needs to be able to be called from the browser.
Avatar of ozo
ozo
Flag of United States of America image

#!/usr/bin/perl
use CGI;
use CGI::Carp qw(fatalsToBrowser);
my $q = new CGI;
print $q->header,
      $q->start_html('Read and write file (part 2)';
open I,"<info.txt" or die "Can't open info.txt $!";
open E,">enter.tab" or die "Can't open enter.tab $!";
print E "Code\tCategory\tDescription\tHomeUrl\tLogoUrl\tSubmitUrl\tMethod\tVarmap\tStaticVars\tSuccess\tDefault";

$/="-------------\n";
while( <I> ){
  chomp;
  @l=split/\n/;
  @l = grep !/<input\s+type=(submit|reset)\b/i,@l;
  @i{"text","hidden"}=();
  for( @l ){
      if( /<input\s+type\s*=\s*(\S*).*\bname\s*=\s*(["']([^"']*)["']|(\S*)).*?\b(value\s*=\s*(["']([^"']*)["']|(\S*))).*>/
      ){
           $i{lc $1} .= "$3$4=$7$8,";
      }elsif( /<input\s+type\s*=\s*(\S*).*\bname\s*=\s*("([^"]*)"|(\S*)).*>/
      ){
           $i{lc $1} .= "$3$4=$3$4,";
      }
  }
  chop @i{"text","hidden"};
  #print E join("\t",$l[0],"General",$l[2],$l[1],"http://yes/image.gif",@l[3,4],@i{"text","hidden"},"0"),"\n";
  print E join("\t",$l[0],"General",$l[2],$l[1],"http://yes/image.gif",@l[3,4],@i{"text","hidden"},"Thank You","0"),"\n";
 
}
close E;
close I;
print $q->end_html;
Avatar of malkie
malkie

ASKER

Software error:
syntax error at C:\Inetpub\wwwroot\cgi-bin\extracthtml\ozo3.cgi line 6, near "'Read and write file (part 2)';"
Execution of C:\Inetpub\wwwroot\cgi-bin\extracthtml\ozo3.cgi aborted due to compilation errors.

For help, please send mail to this site's webmaster, giving this error message and the time and date of the error.

ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of malkie

ASKER

That is great had to make a small change to the paths in the script Thank You again