hears is the scrit im using
#!/usr/bin/perl -w
print "whats your name?\n";
$name = <STDIN>;
sleep (2);
print "nice to meet you \n";
sleep (2);
$n1 = substr($name,0,1);
$n2 = substr($name,1,1);
$n3 = substr($name,2,1);
$n4 = substr($name,3,1);
$n5 = substr($name,4,1);
$n6 = substr($name,5,1);
$n7 = substr($name,6,1);
$n8 = substr($name,7,1);
$n9 = substr($name,8,1);
$n10 = substr($name,9,1);
$n11 = substr($name,10,1);
$n12 = substr($name,11,1);
$n13 = substr($name,12,1);
$n14 = substr($name,13,1);
$n15 = substr($name,14,1);
$n16 = substr($name,15,1);
$n17 = substr($name,15,1);
$n18 = substr($name,16,1);
$n19 = substr($name,17,1);
print "$n1 $n2 $n3 $n4 $n5 $n6 $n7 $n8 $n9 $n10 $n11 $n12";
print "$n13 $n14 $n15 $n16 $n17 $n18 $n19 \n\n";
my $now = gmtime;
print "it is $now\n in greenwich england which is \nfive hour
your best option is to use the CGI perl module.
module download and documentation:
[search.cpan.org...]
The program you are running is compiled with "strict", which means all variables have to be properly declared with "my" or "our" or possibly "vars". Look up the "strict" pragma in the perl documentation or search online.
As far as the tar.gz, file, I have no idea what you are asking.
Here is what they are telling you:
You are using STDIN input to supply data to your program. On the web, this is done by a) submitting form data, and b) parsing out the submitted data to supply it to your program. This is what the CGI module does. This process is called Read and Parse: read in the encoded input stream and parse it out into key/value pairs.
Here's a working web-ified example of your command line program. Compare it with yours and you'll see what it does. Four caveats:
- I changed "name" to "your_name" to avoid any conflicts with HTML documents; forms have an attribute called "name" (which is the "key" for the input data.) If it doesn't confuse the browser, it will confuse the newbie. :-)
- You will see this
qq¦
Look up qq in the perl documentation; basically it means print, or store, everything from here ¦ to here ¦. Note that this board software "breaks" this into a double pipe. All you should have to change if you copy and paste is change these ¦ to the single vertical pipe on your keyboard, just above your enter key. There are four of them in this script.
- When developing from the web, you ALWAYS have to have a content-type header followed by two newlines before anything else prints or it will give you a server error. This is distinctly different than your command line program that just prints to STDOUT.
print "content-type:text/html\n\n";
- The permissions must be set to executable for the script to run via the web: chmod 755 [filename]. Upload it, set the permissions, go to your browser and request the file.
Welcome to perl. :-)
#!/usr/bin/perl
#this script is named cgitest.cgi
use CGI;
$cgi_query = new CGI;
$now = gmtime;
print "content-type: text/html\n\n";
if ($cgi_query->param('your_name') ne '') {
$your_name = $cgi_query->param('your_name');
$n1 = substr($your_name,0,1);
$n2 = substr($your_name,1,1);
$n3 = substr($your_name,2,1);
$n4 = substr($your_name,3,1);
$n5 = substr($your_name,4,1);
$n6 = substr($your_name,5,1);
$n7 = substr($your_name,6,1);
$n8 = substr($your_name,7,1);
$n9 = substr($your_name,8,1);
$n10 = substr($your_name,9,1);
$n11 = substr($your_name,10,1);
$n12 = substr($your_name,11,1);
$n13 = substr($your_name,12,1);
$n14 = substr($your_name,13,1);
$n15 = substr($your_name,14,1);
$n16 = substr($your_name,15,1);
$n17 = substr($your_name,15,1);
$n18 = substr($your_name,16,1);
$n19 = substr($your_name,17,1);
print qq¦
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Enter Your Name</title>
</head>
<body>
<p>Nice to meet you $your_name.</p>
<p>$n1 $n2 $n3 $n4 $n5 $n6 $n7 $n8 $n9 $n10 $n11 $n12</p>
<p>$n13 $n14 $n15 $n16 $n17 $n18 $n19</p>
<p>it is $now\n in greenwich england.</p>
</body>
</html>
¦; #end print qq
}
else {
print qq¦
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Enter Your Name</title>
</head>
<body>
<form method="post" action="cgitest.cgi">
<p>What's your name?</p>
<p><input type="text" name="your_name" id="your_name" value=""></p>
<p><input type="submit" value="Submit"></p>
<p>it is $now\n in greenwich england.</p>
</body>
</html>
¦;
}
if ($cgi_query->param('your_name') ne '') {
$your_name = $cgi_query->param('your_name');
## let's create an array instead of creating all those variables
@letters = split('',$your_name);
print qq¦
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Enter Your Name</title>
</head>
<body>
<p>Nice to meet you $your_name.</p>
<p>
¦;
foreach $l (@letters) { print "$l "; }
print qq¦
</p>
<p>it is $now\n in greenwich england.</p>
</body>
</html>
¦; #end print qq
}
RudyS, medranoenrique, whoever:
Refer back to [webmasterworld.com...] thread.. there are PERL / CGI examples there "you guys" said you got running.
Also same problem more or less:
[webmasterworld.com...]
medranoenrique, it's probably best to form "good habits" from the start and heed this recommendation.
habit I guess, and that the pipe is the least likely of characters to EVER appear in any normal text
-rocknbil
I've got dozens of scripts online that run against pipe delimited ASCII "data bases"... I'm so set in my ways I still use-
print 'Whatever<br>\n';
or
#
$s = 'ever';
print "What$s<br>\n";
#
and consider it daring to use-
#
$lf = '<br>\n';
$s = 'ever';
printf "What%s%s", $s, $lf;
#
...it took me long enough to get used to not using line numbers when I stopped using BASIC.
Gotta try that qq thingy some day.. :-)
#!/usr/local/bin/perl
use CGI;
$query = new CGI;
$var1 = ($query->param("var1"));
$lcseq = lc($var1);
chomp ($lcseq);
$length = length($lcseq);
$SCRIPT_uri = $ENV{'SCRIPT_URI'};
i would like to know what it means
anybody who help thanks ;)
new and param are CGI methods:
[search.cpan.org...]
[search.cpan.org...]
lc, chomp and length are basic perl functions:
[perldoc.perl.org...]
ENV is a special perl variable - a hash containing all environment variables:
[perldoc.perl.org...]
as perl_diver suggested, you should really read up on the basics.
you have done NO preliminary work!
from the Perl Forum Charter [webmasterworld.com]:
Do My Homework posts are not all that welcome.
The first one is the call to the perl interpreter. It tells the CGI gateway where to look to execute perl.
#!/usr/local/bin/perl
This means to include the CGI module for it's use in this script.
use CGI;
This creates a CGI object that will hold all the stuff submitted by the form and store it in the variable "$query.".
$query = new CGI;
This next one requires knowledge that a form exists somewhere that has this field:
Var1: <input type="text" name="var1" value="">
var1 is the "key" for whatever value is entered into this field.
So what is happening here is you are telling your CGI object to extract the value submitted for the form field var1 and store that value in a perl variable, $var1.
$var1 = ($query->param("var1"));
This says to take anything in that value and convert it to lower case. Store the result in $lcseq.
$lcseq = lc($var1);
(Actually this is an extra step. You can just use the original variable $var 1, like $var1 = lc($var1);)
For whatever reason it's being done, this next one does what it says - chomps off the last character of $lcseq. Usually this is only used when reading in text files to chomp off newlines (carriage returns.) Not sure why it would be used here, unless the form field is a textarea.
chomp ($lcseq);
This next one gives a numeric length for $lcseq (number of characters.) For example, if I do this:
$rtfm = "read the manual!";
$len = length($rtfm);
The value of $len should be 16.
$length = length($lcseq);
This next one takes an environment variable, the URI of the script, and stores it in the variable $SCRIPT_uri. There are many envars, all available to any perl web program, besides this is one. Google for environment variables for more info.
$SCRIPT_uri = $ENV{'SCRIPT_URI'};
Sooooo . . . . what this chunk of code does is read and parse the value of some form with a field named var1, does some trivial stuff with it . . . and that's about it, it doesn't really do . . . anything . . . .
i have a question about something that was given to me by RudyS and it was given to him a long time ago i think and he was given this
-medranoenrique
"Give a man a perl script and he processes data for a day,
teach a man perl and he writes code for a lifetime."
- a wise old scripter
A parting bit of advice for medranoenrique and RudyS --- take a copy of The Perl Cookbook, (by Nathan Torkington), out of the library and start at Page 1... By the time you get through the book you will know perl.
$len = length($rtfm);
The value of $len should be 16.
-rocknbil
My interpreter returned a longer length to the $rtfm variable --- you seem to have used the "kinder gentler" $rtm type variable -- possibly you left out a regular expression? e.g.-
#
$rtm = $rtfm;
$rtm =~ s/f(rigg¦uck¦rig)//;
$rtm =~ s/(ing¦in'¦in)//;
#
(pipe fix as usual)..
@lexipixel:
"Give a man a perl script and he processes data for a day,
teach a man perl and he writes code for a lifetime."
- a wise old scripter
"Give a man a fish, and you feed him for a day. Teach a man to fish, you feed him for a life time."
- the Perl Forum Charter [webmasterworld.com]
~~Enrique Medrano~~
#!/usr/local/bin/perl
use CGI;
$query = new CGI;
$var1 = ($query->param("var1"));
$lcseq = lc($var1);
chomp ($lcseq);
$oligolength = length($lcseq);
$SCRIPT_uri = $ENV{'SCRIPT_URI'};
$tm = 0;
$charpos = 0;
until($charpos == $oligolength)
{
$pair = substr($lcseq, $charpos, 2);
if ($pair eq "aa"){$tm += 2.116;}
if ($pair eq "ac"){$tm += 3.068;}
if ($pair eq "ag"){$tm += 2.750;}
if ($pair eq "at"){$tm += 1.862;}
if ($pair eq "ca"){$tm += 3.068;}
if ($pair eq "cc"){$tm += 3.893;}
if ($pair eq "cg"){$tm += 4.591;}
if ($pair eq "ct"){$tm += 2.708;}
if ($pair eq "ga"){$tm += 2.750;}
if ($pair eq "gc"){$tm += 4.739;}
if ($pair eq "gg"){$tm += 3.893;}
if ($pair eq "gt"){$tm += 3.047;}
if ($pair eq "ta"){$tm += 1.227;}
if ($pair eq "tc"){$tm += 2.708;}
if ($pair eq "tg"){$tm += 3.047;}
if ($pair eq "tt"){$tm += 2.116;}
$charpos = $charpos +1;
}
$tm = $tm + 2.5;
print "Content-type: text/html\n\n";
print "<html>";
print "<head><title>tm calculator</title></head>";
print "<body>";
if ($var1 eq '') {
print "<form action=\"$SCRIPT_uri\" method=\"POST\">";
print "Sequence(up to 14 characters, no spaces inbetween or after): <input type=\"text\" name=\"var1\">\n";
print "<input type=\"submit\" value=\"submit\">\n";
print "</form>";
} else {
print "your sequence is $length characters.\n";
print "the tm of your sequence is $tm";
}
print "</body>";
print "</html>";
exit;
1. Never trust user input
2. Treat all user input like poison
3. See rule one and two
When you allow people to send data to your server that is used in a program, you better follow those three rules, because eventually some, uhh..... fool, will test the security of your script, by design or by accident, and then it might be too late.