?
Solved

Read and write file (part 2)

Posted on 2003-03-15
4
Medium Priority
?
200 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
  • 2
  • 2
4 Comments
 
LVL 85

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 85

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

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Question has a verified solution.

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

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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

621 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