F
freedom
I m a newbie in perl and just try to finish an assignment. I generate an
html form with CGI.pm. If the user enter a url in the first textfield, that
url supposed to be loaded wit LWP. In the second text field if the user
enter a tag or a filename it is supposed to search and it should be replaced
whatever user entered in the third field.
The problems:
1.I m getting text document instead of html source code when i enter a url
in the first textfield..
2. I can not do the search and replace in the second and third field
any help please. I will be so thankful
this is my generated form script
#!/usr/bin/perl
use strict;
use CGI qw( :standard );
use CGI::Carp qw(fatalsToBrowser);
print( header() );
print( start_html(-title => 'Online XHTML Change Form' ) );
print <<FORM;
<form action = "start.cgi" method = "post">
<p>Option:
<select name = "option">
<option selected>URL</option>
<option>File</option>
<option>Tag</option>
</select>
<p>URL of page to be changed:
<input name = "url" type = "text" size = "50"></p>
<p>Name of file, tag or url to be changed:
<input name = "text" type = "text" value="$_" size = "50"></p>
<p>Name to be changed:
<input name = "pattern" type = "text" value="$pattern" size = "50"></p>
<input type = "submit" value = "submit">
</form>
FORM
print( end_html() );
this is the html parsing , search and replace. I called it start.cgi
#!/usr/bin/perl
use strict;
use warnings;
use CGI qw( :standard );
use CGI::Carp qw(fatalsToBrowser);
use LWP::UserAgent;
use HTML::TokeParser;
my $url = param( "url" );
my $option = param( "option");
my $agent = new LWP::UserAgent();
my $request = new HTTP::Request( 'GET' => $url );
my $response = $agent->request( $request );
my $document = $response->content();
my $page = new HTML::TokeParser( \$document );
while ( my $token = $page->get_token() ) {
my $type = shift( @{ $token } );
my $url = shift( @{ $token } );
if ($type eq "T" ) {
print( "$url" );
}
}
$_ = param( "text" );
$pattern = param( "pattern" );
if( $option == "URL" ) {
my $string = get($url);
s/$_/$pattern/;
}
if (!$url ) {
print( start_html() );
print( h4( "Url field should not be blank." ) );
print( h4("Please try again.") );
print( "<a href = \"/assign2.cgi\">Go back</a>" );
print( end_html() );
exit();
}
html form with CGI.pm. If the user enter a url in the first textfield, that
url supposed to be loaded wit LWP. In the second text field if the user
enter a tag or a filename it is supposed to search and it should be replaced
whatever user entered in the third field.
The problems:
1.I m getting text document instead of html source code when i enter a url
in the first textfield..
2. I can not do the search and replace in the second and third field
any help please. I will be so thankful
this is my generated form script
#!/usr/bin/perl
use strict;
use CGI qw( :standard );
use CGI::Carp qw(fatalsToBrowser);
print( header() );
print( start_html(-title => 'Online XHTML Change Form' ) );
print <<FORM;
<form action = "start.cgi" method = "post">
<p>Option:
<select name = "option">
<option selected>URL</option>
<option>File</option>
<option>Tag</option>
</select>
<p>URL of page to be changed:
<input name = "url" type = "text" size = "50"></p>
<p>Name of file, tag or url to be changed:
<input name = "text" type = "text" value="$_" size = "50"></p>
<p>Name to be changed:
<input name = "pattern" type = "text" value="$pattern" size = "50"></p>
<input type = "submit" value = "submit">
</form>
FORM
print( end_html() );
this is the html parsing , search and replace. I called it start.cgi
#!/usr/bin/perl
use strict;
use warnings;
use CGI qw( :standard );
use CGI::Carp qw(fatalsToBrowser);
use LWP::UserAgent;
use HTML::TokeParser;
my $url = param( "url" );
my $option = param( "option");
my $agent = new LWP::UserAgent();
my $request = new HTTP::Request( 'GET' => $url );
my $response = $agent->request( $request );
my $document = $response->content();
my $page = new HTML::TokeParser( \$document );
while ( my $token = $page->get_token() ) {
my $type = shift( @{ $token } );
my $url = shift( @{ $token } );
if ($type eq "T" ) {
print( "$url" );
}
}
$_ = param( "text" );
$pattern = param( "pattern" );
if( $option == "URL" ) {
my $string = get($url);
s/$_/$pattern/;
}
if (!$url ) {
print( start_html() );
print( h4( "Url field should not be blank." ) );
print( h4("Please try again.") );
print( "<a href = \"/assign2.cgi\">Go back</a>" );
print( end_html() );
exit();
}