Using Subroutines with CGI::Session::MySQL?

L

L. D. James

On Aug 21, 1:18 am, (e-mail address removed) wrote:

Hi, Xhoster.

Does my last script, the testio produce errors on your computer?

-- L. James
 
M

Mumia W.

[...]
# ----- Code -----
#!/usr/local/bin/perl

use warnings;
use strict;
use CGI qw:)standard);
use Switch;
use CGI::Carp qw(fatalsToBrowser);

print header;

my $count;

if ( open (FILEIN,"testio.out") )
{
$count = <FILEIN> || "0";
close ( FILEIN );
}

open (FILEOUT,">testio.out") || die "Can't open output file...";

sub testio()

Leave off the parentheses. Prototypes are generally not needed with Perl.
{
&menu1();

The ampersand is the old way of calling Perl subs. Don't use it for
modern Perl code unless you know what it does. Read "perldoc perlsub"
$count++;
print "<br>The Count: $count";
print FILEOUT "$count";

Quoting $count is unnecessary; read "perldoc -q quoting."
}

sub menu1()
{
print "<a href=testio.pl?cmd=testio>Testio<a>";
}

my $s = param('cmd') || $ARGV[0];

switch($s)
{
case "testio" { testio() }
else { menu1() }
}

close FILEOUT;
exit;

# ----- Code End -----

-- L. James

Invoking testio.pl without a parameter resets the counter on my system.
Perhaps that was intended.
 
L

L. D. James

sub testio()

Leave off the parentheses. Prototypes are generally not needed with Perl.
{
&menu1();

The ampersand is the old way of calling Perl subs. Don't use it for
modern Perl code unless you know what it does. Read "perldoc perlsub"
$count++;
print "<br>The Count: $count";
print FILEOUT "$count";

Quoting $count is unnecessary; read "perldoc -q quoting."


sub menu1()
{
print "<a href=testio.pl?cmd=testio>Testio<a>";
}
my $s = param('cmd') || $ARGV[0];
switch($s)
{
case "testio" { testio() }
else { menu1() }
}
close FILEOUT;
exit;
# ----- Code End -----
-- L. James

Invoking testio.pl without a parameter resets the counter on my system.
Perhaps that was intended.

Thanks for the references. I'm studying them in detail. Before using
strict and warning I used to always call the subroutines without the
ampersand and parentheses. When I got the bareword not allowed using
strict, I kind of went overboard to avoid errors. But I'll study the
references and clean up my code to use what's required in each
instance.

The resetting of count was incidental. I cut a part of my main from
my program that included enough to duplicate what I did throughout to
get an opinion about the correctness.

I have another question on optimizing, but will start a new topic on
the new subject.

It'll take me a few hours to grab a small part and clean it up so that
it will work without the thousand lines of subroutines that are
intertwined with it.

The problem it takes an extremely long time to take 500 lines of colon
delineated data and update a 15,000 record MySQL table. It takes
between a minute and a half to three minutes.

-- L. James
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top