CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Passing arguments to module's function

 



maciejp
New User

May 1, 2013, 1:30 AM

Post #1 of 7 (739 views)
Passing arguments to module's function Can't Post

Hello. First of all sorry about my English.

I'm trying to write a new module to my program with one function and two arguments from main script: $Mail, $Haslo. Here's code:

Module:

Code
package Own::database; 

use locale;
use strict;
use warnings;

use CGI ':standard';

use Spreadsheet::ParseExcel;

require Exporter;
our @ISA = qw(Exporter);
our @EXPORT = qw(check_base);

sub check_base {
my($Mail, $Haslo) = @_;

my $q = new CGI;

my $parser = Spreadsheet::ParseExcel->new();
my $workbook = $parser->parse('baza.xls');

if ( !defined $workbook ) {
die $parser->error(), ".\n";
}

my $worksheet = $workbook->worksheet(0);
my $pomocnicza=0;

my ( $row_min, $row_max ) = $worksheet->row_range();

for my $row ( $row_min .. $row_max ) {

if ($row == $row_max) {$pomocnicza=1};
my $cell = $worksheet->get_cell($row, 0);
my $value = $cell->value();

if ($value eq $Mail) {
my $cell = $worksheet->get_cell( $row, 1);
my $value = $cell->value();
if ($value eq $Haslo) {
return 1;
last;
}
}
else {
return 0;
}
}
}
1;


Script

Code
#!C:\Strawberry\perl\bin\perl -w 

use locale;
use strict;
use warnings;

use CGI ':standard';

use Spreadsheet::ParseExcel;

use Own::database;

my $q = new CGI;

my $Mail = $q->param('mail');
my $Haslo = $q->param('haslo');

my $checked = check_base($Mail, $Haslo);

if ($checked) {
print redirect('http://localhost/zalogowano.html');
}
else {
print header(-type=>"text/html; charset=ISO-8859-2");
print start_html(-title=>'Organizer',
-lang=>'pl-PL',
-encoding=>'ISO-8859-2');
print '<form action="/cgi-bin/logowanie.cgi" method="post">';
print 'Adres e-mail: ';
print '<br>';
print textfield(-name=>'mail',
-size=>15,
-maxlength=>30);
print '<br>';
print 'Hasło: ';
print '<br>';
print textfield(-name=>'haslo',
-size=>15,
-maxlength=>30);
print '<br>';
print submit(-name=>'Logowanie',
-value=>'Zaloguj');
print '</form>';
print '<form action="http://localhost/index.html" method="link">';
print submit(-name=>'przypomnienie',
-value=>'Przypomnij hasło',
-action=>'przypomnienie.cgi');
print '</form>';
print '<font color="red"> Błędne dane logowania.</font>';
print '<br>';
print a({
-href=>'http://localhost/rejestracja.html'},
'Rejestracja');
print end_html;
}


I'm still getting error:


Code
Use of uninitialized calue $Mail in string eq at../module.pl line 38.


I can't find mistake but my perl programming ability isn's as good as it should. Can you help me, what is wrong?


g4143
Novice

May 1, 2013, 5:51 AM

Post #2 of 7 (733 views)
Re: [maciejp] Passing arguments to module's function [In reply to] Can't Post

Did you check to see if this sets $Mail?


Code
my $Mail = $q->param('mail');



maciejp
New User

May 1, 2013, 8:40 AM

Post #3 of 7 (722 views)
Re: [g4143] Passing arguments to module's function [In reply to] Can't Post

Thanks for reply.

Yes. If whole code is in one file, everything works fine. So, something in passing goes wrong :/


(This post was edited by maciejp on May 1, 2013, 8:41 AM)


FishMonger
Veteran / Moderator

May 1, 2013, 9:18 AM

Post #4 of 7 (713 views)
Re: [maciejp] Passing arguments to module's function [In reply to] Can't Post

Remove this line from the module.

Code
use CGI ':standard';


As well as this one.

Code
my $q = new CGI;



maciejp
New User

May 1, 2013, 9:58 AM

Post #5 of 7 (702 views)
Re: [FishMonger] Passing arguments to module's function [In reply to] Can't Post

Thanks. You're right, that was unnecessary.

But i'm still getting the same error:/


(This post was edited by maciejp on May 1, 2013, 9:59 AM)


FishMonger
Veteran / Moderator

May 1, 2013, 10:09 AM

Post #6 of 7 (699 views)
Re: [maciejp] Passing arguments to module's function [In reply to] Can't Post

Add a couple debug statements.

Dump the value of $Mail just prior to passing it to the sub and immediately after you assign it in the module.


Laurent_R
Veteran / Moderator

May 1, 2013, 10:22 AM

Post #7 of 7 (695 views)
Re: [maciejp] Passing arguments to module's function [In reply to] Can't Post

I do not see anything wrong in the passing of parameters to the function, so, to me, it would seem that either $Mail is not defined when you call the function, or it is lost afterwards (but I fail to see any reason, so that I would think the first solution is more plausible, possibly the statement $q->param('mail') did not work as you acpect). As said by Fishmonger, just print something like "Before function call; value is $Mail\n;" right before the function call and a similar statement within the function right after assigning @_ to your variables.


(This post was edited by Laurent_R on May 1, 2013, 10:25 AM)

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives