473,394 Members | 1,765 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

how do i create OOP perl scripts?

236 100+
Hi All,

How create OOP perl scripts and how to let users select different ouput html template to display the photo that they upload? Including the urls to refer to.

Kindly advise...

Cheers..
Oct 11 '08 #1
31 2699
KevinADC
4,059 Expert 2GB
Your question is way to broad. If you don't know OO programming techniques yet that is where to start, with some OO tutorials or books. Perl comes with several OO tutorials, and a number of perl books discuss how to write OO programs with perl.
Oct 11 '08 #2
happyse27
236 100+
Your question is way to broad. If you don't know OO programming techniques yet that is where to start, with some OO tutorials or books. Perl comes with several OO tutorials, and a number of perl books discuss how to write OO programs with perl.
Hi Kevin,

Any reference sites which for beginners can start? thanks in advance. Cheers..
Oct 12 '08 #3
happyse27
236 100+
just want to be broadbased, but I will branch into uploading / downloading files, reading from db and inserting to db, website security, bandwidth optimization... ... Cheers...
Oct 12 '08 #4
KevinADC
4,059 Expert 2GB
Perl comes with all sorts of tutorials. You can read them online or from your local install of perl. I recommend you buy the "Perl BookShelf Reference" on CD. For online resourses google is your friend. See also:

http://bytes.com/forum/thread790489.html
Oct 12 '08 #5
happyse27
236 100+
Hi Guru,

Thanks again! will go through.


Cheers..
Andrew
Oct 12 '08 #6
happyse27
236 100+
Hi All,

I tried the redirect, but it seemed that it did not work, the below script processes the username and password, and when the username and password is fine, then $test =1, but it just dont redirect to new webpage http://127.0.0.1/cgi-bin/cards2.pl

code that worked as plain redirect script
=============================
Expand|Select|Wrap|Line Numbers
  1. use CGI;
  2. my $query = new CGI;
  3.  
  4.  
  5. my $url = "http://127.0.0.1/cgi-bin/cards2.pl";  
  6.    print "ok";
  7.      print $query->redirect($url); 
  8.  
  9.  
code that did not work
================
Expand|Select|Wrap|Line Numbers
  1. $sql = $dbh->prepare(qq{SELECT * FROM user_reg where user_name = "$user_name"});  
  2.  $sql->execute(); 
  3.  
  4. while (my @data = $sql->fetchrow_array()){  
  5.  
  6. if($data[0] eq $user_name and $data[1] eq $password)
  7.     {
  8.  
  9.  
  10.  
  11.       # Print the date from the first four columns in the table  
  12.       print $data[0], "\t", $data[1], "\t", $data[2], "\t", $data[3], "\t", $data[4], "\t", 
  13.  
  14. $data[5], "<br>";  
  15.       print $data[0], "\t", $data[1], "\t", $data[2], "\t", $data[3], "\t", $data[4], "\t", 
  16.  
  17. $data[5], "\t", $data[6], "\t", $data[7], "\t", $data[8], "\t", $data[9], "\t", $data[10], 
  18.  
  19. "\t", $data[11], "\t", $data[12],  "\t", $data[13], "\t", $data[14], "\t", $data[15], "\t", 
  20.  
  21. $data[16], "\t", $data[17], "<br>"; 
  22.  
  23.       print "login is ok!";
  24.  
  25.       my $test = 1;
  26.  
  27.  
  28.  
  29.      }
  30.  
  31.     else
  32.  
  33.     {
  34.         print "not ok";
  35.         print "username : $user_name";
  36.         print "password : $password";
  37.  
  38.     }
  39.  
  40. }
  41.  
  42. if($test = 1)
  43. {
  44. print "ok";
  45. #my $url = "http://127.0.0.1/cgi-bin/cards2.pl";  
  46.  
  47.  
  48. # print $query->redirect($url);
  49.  
  50. print $query->redirect(-location=>'http://127.0.0.1/cgi-bin/cards2.pl',
  51.                           -nph=>1,
  52.                           -status=>301);
  53.  
  54.  
  55. }
  56.  
Dec 25 '08 #7
happyse27
236 100+
hi all,

The above code that did work, I got this in the webpage display

Thanks in advance,
Andrew


login is ok!okHTTP/1.1 301 Server: Apache/2.2.9 (Win32) Status: 301 Date: Fri, 26 Dec 2008 07:35:19 GMT Location: http://127.0.0.1/cgi-bin/cards2.pl 0
Dec 25 '08 #8
happyse27
236 100+
Hi All,

I found the answer, if the html form is printed, then the redirect cant work. The conditional if still there, the redirect can still work...


Cheers...
Andrew
Dec 26 '08 #9
KevinADC
4,059 Expert 2GB
this line in your code is wrong:

if($test = 1)

it should be:

if($test == 1)

= assigns a value
== compares values

you also have:

my $test = 1;

but its inside a block of code making it "invisible" later in the script outside the block.
Dec 26 '08 #10
happyse27
236 100+
Hi Kevin / all,

Ok. noted thanks!

Btw 2 more queries...

1) $sql = $dbh->prepare(qq{SELECT * FROM user_reg where user_name = "$user_name"}); , do the equal here must be == also?

2) How to make the website's user authenticate and timeout after that...


Best Rgds,
Andrew
Dec 26 '08 #11
happyse27
236 100+
Hi Kevin / all,

The item 1) above i have to use = only i guess, tried eq and == cant work.

For item 2) i found the code below, but it cant really show the timeout, not sure what is the problem.

Error log : [Fri Dec 26 21:13:14 2008] [error] [client 127.0.0.1] script not found or unable to stat: D:/Program Files/Apache Software Foundation/Apache2.2/cgi-bin/pngfix.htc
[Fri Dec 26 21:13:14 2008] [error] [client 127.0.0.1] File does not exist: D:/Program Files/Apache Software Foundation/Apache2.2/htdocs/bv01011.gif, referer: http://127.0.0.1/cgi-bin/timeout30.pl


Access log : 127.0.0.1 - - [26/Dec/2008:21:13:14 -0800] "GET /cgi-bin/main3.pl HTTP/1.1" 200 6749


Expand|Select|Wrap|Line Numbers
  1.  #!c:\perl\bin\perl.exe 
  2. #!/usr/bin/perl 
  3.  
  4. # Note that if you do this, you must explicitly
  5. # export everything you want to use:
  6. use LWP::Simple qw($ua get);
  7.  
  8. $ua->timeout(30);
  9. my $webpage = "http://127.0.0.1/cgi-bin/main3.pl";
  10.  
  11.  
  12. print "Content-type: text/html\n\n";
  13. my $html = get $webpage || die "Timed out!";
  14.  
  15. print "$html";
  16.  
  17.  
Dec 26 '08 #12
KevinADC
4,059 Expert 2GB
@happyse27
Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM user_reg where user_name = "$user_name"
The above is an sql query, its not perl code. As far as I know "=" is the correct syntax for the sql query.

I can't help with question #2.
Dec 26 '08 #13
happyse27
236 100+
Hi Kevin,

Np... Cheers... Thanks again.


Best Rgds,
Andrew
Dec 26 '08 #14
numberwhun
3,509 Expert Mod 2GB
I have not done much (yet) with website authentication (for #2), but did a quick Google search and found a Perl Module for handling it using Apache.

I don't have any experience with the module but I figured I would throw it your way. Also, there seems to be a number of other possible links from the Google search for you to search through as well.

Happy Holidays!

Jeff
Dec 26 '08 #15
happyse27
236 100+
Hi Jeff,

Thanks and Happy Holiday... This module you recommended unfortunately not in activestate perl's listed module to test the webpage timeout / after login say 10 mins no user's web activity timeout. I found this link CGI::Session::Tutorial - Extended CGI::Session manual - search.cpan.org

But got apache error log :
[Mon Dec 29 02:41:30 2008] [error] [client 127.0.0.1] script not found or unable to stat: D:/Program Files/Apache Software Foundation/Apache2.2/cgi-bin/cgi-session.pl

and access log error :
127.0.0.1 - - [29/Dec/2008:02:37:05 -0800] "GET /cgi-bin/cgi-session.pl HTTP/1.1" 404 220

Expand|Select|Wrap|Line Numbers
  1. #!c:/perl/bin/perl.exe
  2. #!/usr/local/bin/perl
  3.  
  4.  
  5. print "Content-type: text/html\n\n";
  6.  
  7. # Object initialization:
  8.     use CGI::Session;
  9.     $session = new CGI::Session() or die CGI::Session->errstr;;
  10.  
  11.     $CGISESSID = $session->id();
  12.  
  13.     #New
  14.     $cookie = $query->cookie( -name   => $session->name,
  15.                               -value  => $session->id );
  16.     print $query->header( -cookie=>$cookie );
  17.  
  18.     #new 
  19.     CGI::Session->name("SID");
  20.     $session = new CGI::Session();
  21.  
  22.     # send proper HTTP header with cookies:
  23.     print $session->header();
  24.  
  25.     #New
  26.     printf ("<a href=http://127.0.0.1/cgi-bin/signin.pl">click me</a>", $session->name, 
  27.  
  28. $session->id);
  29.  
  30.     #New
  31.     $session = new CGI::Session( $sid );
  32.     $session = new CGI::Session( "serializer:freezethaw", $sid );
  33.     $session = new CGI::Session( "driver:mysql", $sid, {Handle=>$dbh} );
  34.  
  35.     #New
  36.     $cgi     = new CGI::Simple();
  37.     $session = new CGI::Session ( $cgi );
  38.     $session = new CGI::Session( "driver:db_file;serializer:storable", $cgi);
  39.     # etc
  40.  
  41.     #New
  42.      my $name = $cgi->param('username');
  43.     $session->param('username', $name);
  44.  
  45.     #New
  46.     $session->save_param();
  47.  
  48.     # storing data in the session
  49.     ##$session->param('f_name', 'Sherzod');
  50.     # or
  51.     ##$session->param(-name=>'l_name', -value=>'Ruzmetov');
  52.  
  53.     # flush the data from memory to the storage driver at least before your
  54.     # program finishes since auto-flushing can be unreliable
  55.     $session->flush();
  56.  
  57.     #New
  58.     $name = $session->param("name");
  59.     printf "<input type=\"text\" name=\"name\" value=\"%s\" />", $name;
  60.  
  61.     #New
  62.     @fruits = @{ $session->param('fruits') };
  63.  
  64.     #New
  65.     $session->load_param($cgi, ["fruits"]);
  66.  
  67.     #New
  68.     print $cgi->checkbox_group(fruits=>['apple', 'banana', 'apricot']);
  69.  
  70.     #New
  71.     $template = new HTML::Template(filename=>"some.tmpl", associate=>$session);
  72.     print $template->output();
  73.  
  74.     #NEw
  75.     Hello <a href="mailto:<TMPL_VAR email>"> <TMPL_VAR first_name> </a>!
  76.  
  77.     #New
  78.     $session->clear(["~logged-in", "email"]);
  79.  
  80.     #New
  81.     $email = $session->param("email");
  82.  
  83.     # retrieving data
  84.     ##my $f_name = $session->param('f_name');
  85.     # or
  86.     ##my $l_name = $session->param(-name=>'l_name');
  87.  
  88.     # clearing a certain session parameter
  89.     ##$session->clear(["l_name", "f_name"]);
  90.  
  91.     # expire '_is_logged_in' flag after 10 idle minutes:
  92.     ##$session->expire('is_logged_in', '+10m')
  93.  
  94.     # expire the session itself after 1 idle hour
  95.     $session->expire('+1h');
  96.  
  97.     # delete the session for good
  98.     $session->delete();
  99.  
  100.  
Dec 28 '08 #16
happyse27
236 100+
kindly give me some pointers... cheers...
Dec 28 '08 #17
numberwhun
3,509 Expert Mod 2GB
@happyse27
First, patience. They are a virtue. This is the holiday season and most of us probably have plans for the holiday season and answers may not come as quick as you may expect.

Second, If Apache is complaining that it cannot find the script then you need to troubleshoot that. You are on Windows, so it isn't the same as Unix, so bear with me.

You need to find out where the cgi-bin directory that you are supposed to put your scripts in is located. This will be in your httpd.conf file, the apache configuration file.

That is where I would suggest you start. Windows is a funky beast to try and get LAMP working on.

Regards,

Jeff
Dec 28 '08 #18
happyse27
236 100+
Hi Sir,

Thanks. I was not rushing anyone, I forgot to ask question although I presented the case, so I posted a second post to ask the questions for pointers. I had realized that this site needs some time to respond as some of the experts and moderators are not online sometimes... Cheers...

Btw, what is LAMP? Cheers...


Best Rgds,
Andrew
Dec 29 '08 #19
numberwhun
3,509 Expert Mod 2GB
@happyse27
LAMP stands for Linux Apache Mysql PHP/Perl/Python. Its your basic web development environment. Its easy to get it going and running on unix, but on Windows, it tends to be a bit more of a pain. There are prebuilt installations of it for Windows that somewhat simplify it, you just have to search google for something like "lamp on windows".

Regards,

Jeff
Dec 29 '08 #20
happyse27
236 100+
Thanks! Sir... :)......
Jan 2 '09 #21
happyse27
236 100+
Hi All,

1) What are the perl module that can easily interface with smtp server?

2) And for web hosting company, do they usually provide free smtp that can send and receive unlimited emails or even sms as we would buy a domain package with them... need help as I could not find free smtp server in the web to test my perl email program...

3) Any suggestion?? Cheers...

4) I cant post new posting again :|

Kindly assist on the above.


Cheers...
Andrew
Jan 28 '09 #22
numberwhun
3,509 Expert Mod 2GB
Andrew,

You really need to read your private messages (see the inbox link at the top of your page) and respond to me accordingly!

Regards,

Jeff
Jan 28 '09 #23
happyse27
236 100+
hi sirs,

I did respond from my private email to forum support email saying that this website somehow due to bugs does not allow me to post new postings... that's why i added here.. But these are perl related issue for smtp and other things above which I REALLY need help. Please kindly assist.


Thanks in advance!
Andrew
Jan 28 '09 #24
numberwhun
3,509 Expert Mod 2GB
@happyse27
I don't want to do this in the thread, but you seem to not want to read the messages I have sent to your inbox here on bytes.com (again, please click on the "inbox" link at the top of the page to see the messages I have sent you).

1. You need to regularly check for messages in your inbox. That is how we contact you outside of these threads. The last message I sent (a while ago), I requested that you message me back to let me know that you read and understand it. You have not done so and that is not good. There is a formal warning in there you need to read.

2. You keep saying that you aren't able to post new threads, yet I seem to see threads started by you on January 9th and January 17th. From what I can tell, you are definitely able to post new threads and need to abide by the rules of this site!

Although you say the issues are related to your issue, the questions and the way you asked them were specific to the other topics where I moved the posts and started their new threads. If it is specifically a Perl issue, fine, but when you are trying to run a Perl program and something else isn't cooperating, like Apache and you then ask an Apache specific question, that is the problem. Do you see and understand?

Now, please go read your messages that I have sent you and reply.

Regards,

Jeff
Jan 28 '09 #25
KevinADC
4,059 Expert 2GB
Modules you can look into:

Net::POP3
Net::SMTP
Jan 28 '09 #26
happyse27
236 100+
Hi Sirs,

Thanks... You can check your source codes or get more users to feedback, some days I can post, HOWEVER some days I cant(which I pasted the GUI to show you in some of my postings)... And I cant easily find the new post icon in the website(but this is not the main problem as I really cant post new post as the website did not allow me in the permission grant.)

And one more bug is when I logged in, it will not allow me to go forum and inform that I have login in already.

Hi Kevin,

Thanks. But does the 2 modules allow me to test to send emails to myself or other users as I understand it needs public smtp server to do the job...


Cheers...
Andrew
Jan 29 '09 #27
happyse27
236 100+
btw, I did reply emails previously three to four different times, not sure why your email account not receive. Please check your logs...

I swear I did all the above, I will try to separate the topics, but please kindly be understanding towards the problems with bytes website that I am facing, if I am not allowed to post as the permission rights got problem, then what is the way or procedure to allow me to post again. Let's work on these... Cheers...
Jan 29 '09 #28
happyse27
236 100+
btw, one more thing, your website did allow me to key in private message reply regardless of any moments, And the posting of my replies to you also didnt work. I wish I had the means to check which posting I reply...


Cheers...
Jan 29 '09 #29
happyse27
236 100+
Hi Kevin,

I could not find net::smtp in perl package manager, but the below codes worked fine, is it the same effect? I guess I have to use gmail account to test my smtp problem as they provide free smtp server.



Cheers..
Andrew

Expand|Select|Wrap|Line Numbers
  1.  
  2. #!c:/perl/bin/perl.exe -w  
  3.  
  4.    use strict;  
  5.    use warnings;   
  6.  
  7.    use Mail::Sender::Easy qw(email);  
  8.  
  9.     print "Content-type: text/plain\n\n"; 
  10.  
  11.  
  12.     email({ 
  13.         'from'         => 'EMAIL REMOVED FOR YOUR PROTECTION', 
  14.         'to'           => 'EMAIL REMOVED FOR YOUR PROTECTION', 
  15.         'cc'           => 'IP REMOVED FOR YOUR PROTECTION', 
  16.         'subject'      => 'Perl is great!', 
  17.         'priority'     => 2, # 1-5 high to low 
  18.         'confirm'      => 'delivery, reading', 
  19.         'smtp'         =>', 
  20.         'port'         => 25, 
  21.         #'auth'         => 'LOGIN', 
  22.         'authid'       => 'andrew', 
  23.         'authpwd'      => 'PASSWORD REMOVED FOR YOUR PROTECTION', 
  24.         '_text'        => 'Hello *World5* :)',     
  25.         '_html'        => 'Hello <b>World</b> <img src="cid:smile1" />', 
  26.         '_attachments' => { 
  27.             'smiley.gif' => { 
  28.                 '_disptype'   => 'GIF Image', 
  29.                 '_inline'     => 'smile1', 
  30.                 'description' => 'Smiley', 
  31.                 'ctype'       => 'image/gif',     
  32.                 'file'        => 'D:/program files/Apache Software  
  33.  
  34. Foundation/Apache2.2/htdocs\smiley.gif', 
  35.             }, 
  36.             #'mydata.pdf' => { 
  37.                 #'description' => 'Data Sheet',   
  38.                 #'ctype'       => 'application/pdf', 
  39.                 #'msg'         => $pdf_guts, 
  40.             #}, 
  41.         }, 
  42.     }) or die "email() failed: $@"; 
  43.  
  44.  
Jan 29 '09 #30
numberwhun
3,509 Expert Mod 2GB
Andrew,

I have now edited your most recent post for the following reasons:

1. You had multiple real world email addresses in the post. Emails are not allowed for your protection.
2. You had a password in the posting.
3. You had an IP address in the post. (albeit a local, non-internet accessible address, but an IP none the less).

You REALLY need to think about your security when you post. These forums are publicly searchable and any information here is scrapable.

Here is a link to our Posting Guidelines. If you haven't read them, please do. I doubt you have, otherwise you would be more abiding by them when posting.

Now that you have the link to them, you need to follow them.
Jan 29 '09 #31
numberwhun
3,509 Expert Mod 2GB
Since a solution has been reached, I am closing this thread.
Jan 29 '09 #32

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Sandman | last post by:
The subject says it all. I am doing a: I have a perl script in which I am using a ReadParse routine that parses the $ENV{'QUERY_STRING'} or $ENV{'CONTENT_LENGTH'} which are two variables passed...
42
by: Fred Ma | last post by:
Hello, This is not a troll posting, and I've refrained from asking because I've seen similar threads get all nitter-nattery. But I really want to make a decision on how best to invest my time....
1
by: sm00thcrimnl13 | last post by:
if i have windows 2000 and know how to write perl scripts, how to i actuvate the script through perl?
1
by: Al Belden | last post by:
Hi all, I've been working on a problem that I thought might be of interest: I'm trying to replace some korn shell scripts that search source code files with perl scripts to gain certain features...
1
by: Jay Warmack | last post by:
I have some large legacy scripts written in PERL and am looking for a way to either convert them to .Net or develope and adapter so that new ASP.Net and CSharp components can access the business...
12
by: rurpy | last post by:
Is there an effcient way (more so than cgi) of using Python with Microsoft IIS? Something equivalent to Perl-ISAPI?
8
by: vj | last post by:
I've been given a project which requires writing scripts that need to be run on over 3000 servers. Only about 15% of them have python installed on them. While all/most of them will have perl. ...
3
by: MarkW | last post by:
I hope this is the correct place to post this: I am developing a web site for a e-commerce business I will be running. The site I'm setting up will be 50% store, 50% content. I'm not sure which...
4
by: Patricia Mindanao | last post by:
I want to call cgi perl scripts on my web hosters server from my HTML web pages (on the the web hosters server too). It occurs sometimes (especially during development phase) that these cgi-perl...
4
by: billb | last post by:
I installed a perl extension for PHP to use some perl inside my php primarily because I have perl working with oracle and not php and oracle. So I want to use my old perl scripts, and use the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.