For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > April 2007 > need some help using strict??









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author need some help using strict??
FamiLink Admin

2007-04-27, 9:58 pm

I am trying to verify a credit card number format with the following:
(below) but I am getting errors like:

Global symbol "%r" requires explicit package name at ./modmember.cgi line
681.
Global symbol "%r" requires explicit package name at ./modmember.cgi line
683.
Global symbol "%r" requires explicit package name at ./modmember.cgi line
688.
Global symbol "%r" requires explicit package name at ./modmember.cgi line
688.
Global symbol "%r" requires explicit package name at ./modmember.cgi line
688.
Global symbol "$r2" requires explicit package name at ./modmember.cgi line
689.
Global symbol "%r" requires explicit package name at ./modmember.cgi line
689.
Global symbol "$r2" requires explicit package name at ./modmember.cgi line
691.
Global symbol "$r2" requires explicit package name at ./modmember.cgi line
691.




my $r = reverse $ccnumber; #line 678...
for my $i(0 .. 15) {
if ($i % 2 != 0) {
$r{$i} = 2 * substr($r,$i,1); #line 681
}else {
$r{$i} = substr($r,$i,1); #line 683
}
}

for my $i(0 .. 15) {
if ($r{$i}> 9){$r{$i}=$r{$i}-9} # line 688
my $r2 = $r2 + $r{$i}; # line 689
}
if ($r2 == 0 || $r2 % 10 != 0) { #line 691
$page .= p ("Error: Credit Card Number is not correct.
Please check.")
. editing_form ();
return ($page);
}


I marked the lines. This works without strict. Any Ideas?

Ryan

Tom Phoenix

2007-04-27, 9:58 pm

On 4/27/07, FamiLink Admin <webmaster@familink.com> wrote:

> I am trying to verify a credit card number format with the following:
> (below) but I am getting errors like:
>
> Global symbol "%r" requires explicit package name at ./modmember.cgi line
> 681.


This is because, under 'use strict', you must declare %r in some way;
you can't simply start using it unexpectedly on line 681. The typical
way to fix this is to locate the logical beginning of that variable's
scope and add a line like this:

my(%r, $any_others);

Now you've declared the variables %r and %any_others you need for that
scope, so you won't surprise Perl and get those "requires explicit
package name" messages.

Hope this helps!

--Tom Phoenix
Stonehenge Perl Training
usenet@DavidFilmer.com

2007-04-27, 9:58 pm

On Apr 27, 4:56 pm, webmas...@familink.com (FamiLink Admin) wrote:
> my $r = reverse $ccnumber; #line 678...

....
> $r{$i} = 2 * substr($r,$i,1); #line 681


You declared $r, which is a scalar variable. You never declared %r,
which is a hash, even thouh you reference individual values as $r{key}
(because individual values are scalars). $r and %r are completely
different variables.

Try adding this:
my %r;

--
David Filmer (http://DavidFilmer.com)

Randal L. Schwartz

2007-04-28, 6:58 pm

>>>>> ""FamiLink" == "FamiLink Admin" <webmaster@familink.com> writes:

"FamiLink> I am trying to verify a credit card number format with the following: (below)
"FamiLink> but I am getting errors like:

Why not just use Business::CreditCard?

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com