im a newb perl user

  • dreamer7
  • Student
  • Student
  • dreamer7
  • Posts: 95
  • Loc: UK

Post 3+ Months Ago

ok wel ive just started looking at perl cgi and ive done a tutorial type thing on it so i know how to do certain things like turning things into arrays and hashs but it was only a basic tutorial and it only got up to how to open, close and rename files and directories. What i want to know is how to use functions like param and things like that because there is a specific way u set it up like my $something =param("something") i take it cos i dont know much about this can someone tell me what it does exactly. Also im planning on making a form which has a some fields and an upload part to it if anyone has some code or can tell me how to mix them both it cud b useful and is there a way u can save the information as a html page perhaps im goin in at the deep end before u say lol but i think ill b gd at it one day (hopefully)
d7
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9099
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

dreamer7 wrote:
What i want to know is how to use functions like param and things like that because there is a specific way u set it up like my $something =param("something") i take it cos i dont know much about this can someone tell me what it does exactly.


I am not even sure what you are talking about. Is "param" supposed to be some perl function? or are you just using param as an example when in fact it might be something like:

Code: [ Select ]
$somevar = somefunction("string to pass");


If so that is exaclty how you do it. In your function you write though you would have to make sure you read read the passed variable by doing something like

Code: [ Select ]
sub somefunction {

  my $localvar = shift;
  #now you can use $localvar where ever you want in this function.
  #in this case $localvar would have a value of "string to pass"

}
  1. sub somefunction {
  2.   my $localvar = shift;
  3.   #now you can use $localvar where ever you want in this function.
  4.   #in this case $localvar would have a value of "string to pass"
  5. }


Basically what you use functions for is for code that you might repeatedly use throughout your perl script. Instead of writing your code over and over and over, you could simply create a function (or well they call them "sub routines" in perl), and then you would just call the function each time you want to do some task. Saves alot of time and makes things more organized.
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9099
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

dreamer7 wrote:
Also im planning on making a form which has a some fields and an upload part to it if anyone has some code or can tell me how to mix them both it cud b useful and is there a way u can save the information as a html page perhaps im goin in at the deep end before u say lol but i think ill b gd at it one day (hopefully)


Yeah for a beginner I think you might be getting yourself into some complicated stuff here. For the fields in the form you will need to use the Perl CGI module or have a sub routine which can parse the data.

If you are wanting to upload stuff through the form then you will need to make sure in your html that you have the enctype='multipart/form-data'. So for example you might start your form like:

Code: [ Select ]
<form action="yourcgiscript.cgi" method="post" enctype='multipart/form-data' name="yourForm">


Next you will need to make sure that your cgi script knows how to handle enctype data, as its different than regular parsed data. I think the CGI perl module can handle that for you. I do not know the syntax offhand. You could also write your own sub routine or use one someone else has written. You can find a prewritten subroute to handle uploaded data here:

http://cgi-lib.stanford.edu/cgi-lib/

Once you have that though you will have to figure out how to use that as well. I really don't think its the best thing for a beginner to jump right into, but I am sure if you can figure it out, you will learn alot in your struggle to get there :)
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9099
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

dreamer7 wrote:
... and is there a way u can save the information as a html page


Yes you could parse through the data and write your own subroutines which would instruct your script to write all the data to a file which you could simply have as a .html file.
  • dreamer7
  • Student
  • Student
  • dreamer7
  • Posts: 95
  • Loc: UK

Post 3+ Months Ago

lol i've done a lot since then i found out what param was as well it is when u reference something simply its done like this using the CGI module :
Code: [ Select ]
$something->param('formfield');

and also since then i have made some of my own email and saving to text file scripts using the CGI module. I thought i made some decent progress in it :D even bought 3 books lol
thx for the help though
d7
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9099
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

Yes now that makes more sense :)

Post Information

  • Total Posts in this topic: 6 posts
  • Users browsing this forum: No registered users and 80 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.