?
Solved

Read and write file (part 2)

Posted on 2003-03-15
4
Medium Priority
?
192 Views
Last Modified: 2010-03-05
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.
0
Comment
Question by:malkie
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 8142373
#!/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;
0
 

Author Comment

by:malkie
ID: 8142680
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.

0
 
LVL 84

Accepted Solution

by:
ozo earned 500 total points
ID: 8144468
$q->start_html('Read and write file (part 2)');
0
 

Author Comment

by:malkie
ID: 8146282
That is great had to make a small change to the paths in the script Thank You again
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question