Click to See Complete Forum and Search --> : A Simple CGI/Perl Question... VERY SIMPLE!
oririsdarkstar
09-09-2004, 08:45 PM
I want to create a page using Perl... So that I can excess it with something like ?page=home or something...
So far, this is all I got: #!/usr/bin/perl
print "Content-type: text/html\n\n";
&action;
&home;
sub home {
print "
Hello!
<form method="post">
<input type="submit" value="Variations of Hi" name="vh">
</form>
";
}
sub action {
if ($in{'vh'}) {
print qq~
adsf;lajsdl;fkjas;dljf;lajsd;lff
~;
}
I figured that I'm wrong, so please help me!
silent11
09-10-2004, 01:10 PM
a trivial example
#!/usr/bin/perl
# this is untested code
# page.pl
use strict;
use CGI ':standard';
my $page = param('page');
print header, start_html($page);
if (defined $page) {
if ($page eq 'home') {
print h1("You requested the $page page.");
}
else {
print h1("The page, $page doesn't exist.");
}
}
else {
print h1("click a link to go to a page...");
}
for (qw/home contact download/){
print a({-href=>'page.pl?page=' . $_},$_),br;
}
print end_html;
oririsdarkstar
09-10-2004, 08:53 PM
Hm. That works wonderful...
But, I still have a question: How do I create the seperate pages? (page.pl?page=download)
silent11
09-10-2004, 09:57 PM
did you notice this in the code?
if ($page eq 'home') {
print h1("You requested the $page page.");
}
else {
print h1("The page, $page doesn't exist.");
}
They are essentially 2 seperate pages.
This code below will make a *download* page:
#!/usr/bin/perl
# this is untested code
# page.pl
use strict;
use CGI ':standard';
my $page = param('page');
print header, start_html($page);
if (defined $page) {
if ($page eq 'home') {
print h1("You requested the $page page.");
}
elsif ($page eq 'download') {
print h1("You requested the $page page."),
b('You can put anything you want on this page!'),br,
b('notice how it\'s different from the *home* page?'),
hr(),
p('Hope this helps!');
}
else {
print h1("The page, $page doesn't exist.");
}
}
else {
print h1("click a link to go to a page...");
}
for (qw/home contact download/){
print a({-href=>'page.pl?page=' . $_},$_),br;
}
print end_html;
oririsdarkstar
09-10-2004, 10:06 PM
But now the lines:
for (qw/home contact download/){
print a({-href=>'page.pl?page=' . $_},$_),br;
}
print end_html;
Are giving me hell.
silent11
09-11-2004, 07:02 PM
ok
first off... Do you know what the CGI.pm module is? it's a perl library that makes alot of things simpler for you when building websites in perl. Read the documentation and learn it well.
Notice we call this module at the top. For simplicity I've used the non OO, ':standard' set of functions.
use CGI ':standard';
now for the part at the end:
for (qw/home contact download/){
print a({-href=>'page.pl?page=' . $_},$_),br;
}
print end_html;
first off we start with a for loop, we loop over the values, 'home', 'contact' and 'download'. I just added this little part to make us some links. For each value in the list we are going to make a list with it.
now ever time we iterate over a value the current value is set to $_, pronounced, 'dollar sign, underscore'.
the CGI module allows us to make <a> tags with the a() method, that I used above.
We just used that method to make a link for each value in our for loop. If you're still not getting it go read up on the CGI docs at search.cpan.org, or perldoc.com. Just type in CGI into the search box and read the man page.
oririsdarkstar
09-12-2004, 12:48 AM
Thanks. I know that you proably think I'm a dumbnut or something... =P
silent11
09-13-2004, 11:13 AM
sorry if I came across harsh. I wasn't trying to be.