Ugh. Any mod_perl or MySQL coders/users in the house? *frustrated*

yllus

Elite Member & Lifer
Aug 20, 2000
20,577
432
126
I know, I know. I should have started off with PHP in the first place. Of course being 10,000+ lines of code in using Perl under mod_perl that's no longer an option... :p

Okay, so I've read and read and read one more time all of the documentation available for mod_perl, but there are some basic questions I still am not sure about. Here's my list.

1. Pertains to the common my() Scoped Variable issue. If I've got variables within subroutines, all scoped with my(), are those variable values expiring at the end of execution for that specific user? The variable persistance thing is one hell of a piss-off. :p

2. Using mod_perl to interact with MySQL using DBI and DBD::mysql. The largest text block I seem to be able to transmit from a Web form through the DBI into MySQL is about 1200 characters long. I've tried upping the max_allowed_packet variable in MySQL's configuration to an enormous 10048576 - no help. How can I transmit large blocks of text from my Web form into MySQL, where is the cutoff occurring?

HELP! :D
 

Ameesh

Lifer
Apr 3, 2001
23,686
1
0
1) so if you declare your variables inside the function their scope should be in the function meaning that once you exit the function the variable is out of scope. at least thats the convention used in almost every modern programming language.

2) i dunno this sounds specific to mysql.
 

yllus

Elite Member & Lifer
Aug 20, 2000
20,577
432
126
Originally posted by: manly
What app are your writing?
It's very simple forum software. Wrote it myself because there's not much mod_perl + Win32 compatible forum software that's free to boot. And this way I can integrate my user DB with the forum's.

Ameesh: That's what one would think, but mod_perl is pretty messed...
 

Ameesh

Lifer
Apr 3, 2001
23,686
1
0
Originally posted by: yllus
Originally posted by: manly
What app are your writing?
It's very simple forum software. Wrote it myself because there's not much mod_perl + Win32 compatible forum software that's free to boot. And this way I can integrate my user DB with the forum's.

Ameesh: That's what one would think, but mod_perl is pretty messed...

so your variable is in scope still? im not sure i understand what the problem is?
 

yllus

Elite Member & Lifer
Aug 20, 2000
20,577
432
126
my() creates a lexically-limited non-package-based scalar, array, or hash -- when the scope of definition is exited at compile-time, the variable ceases to be accessible. Any references to such a variable at runtime turn into unique anonymous variables on each scope exit.

I don't understand what that means anymore. :(
 

Ameesh

Lifer
Apr 3, 2001
23,686
1
0
Originally posted by: yllus
my() creates a lexically-limited non-package-based scalar, array, or hash -- when the scope of definition is exited at compile-time, the variable ceases to be accessible. Any references to such a variable at runtime turn into unique anonymous variables on each scope exit.

I don't understand what that means anymore. :(

ok it is fvcked up, what it means is this:


you can decalre a variable, array, or hash, in your code you can access it by name in that function scope just fine, but outside that function you cannot. at runtime if you have a reference or alias type pointing to that variable you can still use it.

what this means is that if you pass a pointer of a local variable out from a function, you can still access it and it will not be overwritten until your reference type that is aliasing the local var goes out of scope.

this would not work in c,c++,c#,java , etc. i highly reccomend you do not program like this as it will get you into a very very bad habit.
 

Descartes

Lifer
Oct 10, 1999
13,968
2
0
my() creates a lexically-limited non-package-based scalar, array, or hash -- when the scope of definition is exited at compile-time, the variable ceases to be accessible. Any references to such a variable at runtime turn into unique anonymous variables on each scope exit.

I don't understand what that means anymore.

It simply means that a variable declared in a block with my makes it local (or in C/C++ vernacular, automatic) to the block. When the block exits, it's no longer defined. e.g.

{
open(BODY, "<$inputFilename") or die("Unable to open $inputFilename");
local $/;
undef $/;
my $body = <BODY>;
close(BODY);
}

[edit]Ameesh already got it...[/edit]
 

Ameesh

Lifer
Apr 3, 2001
23,686
1
0
Originally posted by: Descartes
my() creates a lexically-limited non-package-based scalar, array, or hash -- when the scope of definition is exited at compile-time, the variable ceases to be accessible. Any references to such a variable at runtime turn into unique anonymous variables on each scope exit.

I don't understand what that means anymore.

It simply means that a variable declared in a block with my makes it local (or in C/C++ vernacular, automatic) to the block. When the block exits, it's no longer defined. e.g.

{
open(BODY, "<$inputFilename") or die("Unable to open $inputFilename");
local $/;
undef $/;
my $body = <BODY>;
close(BODY);
}
#$body should be 'unique anonymous' as used in the definition -- i.e. undefined


dont forget the last part: Any references to such a variable at runtime turn into unique anonymous variables on each scope exit.

 

manly

Lifer
Jan 25, 2000
13,079
3,838
136
Originally posted by: yllus
Any references to such a variable at runtime turn into unique anonymous variables on each scope exit.
WTF does that mean? The spec is to turn any such references into a "dangling pointer" of sorts?

As far as question #2, is this a limit of DBI or is it due to the mySQL table schema? I.e. you shouldn't assume VARCHAR can store more than 256 chars on any ANSI SQL RDBMS. Does your design use CLOBs?
 

Ameesh

Lifer
Apr 3, 2001
23,686
1
0
Originally posted by: manly
Originally posted by: yllus
Any references to such a variable at runtime turn into unique anonymous variables on each scope exit.
WTF does that mean? The spec is to turn any such references into a "dangling pointer" of sorts?

As far as question #2, is this a limit of DBI or is it due to the mySQL table schema? I.e. you shouldn't assume VARCHAR can store more than 256 chars on any ANSI SQL RDBMS. Does your design use CLOBs?

read my post, i explained it as best i could.
 

Balthazar

Golden Member
Apr 16, 2000
1,834
0
0
I once had issues with IE not allowing more than x chars, I seem to recall it being somewhere around that range....worth a thought.
 

manly

Lifer
Jan 25, 2000
13,079
3,838
136
Originally posted by: Ameesh

read my post, i explained it as best i could.
I'd glanced over your post, and it seems neither one of us are perl hax0rs (I'm just reading into it for "fun").

From the Perl Reference:
The phrase "lexical variable" is a bit of a misnomer, we are really talking about "lexical symbols". The data can be referenced by a global symbol too, and in such cases when the lexical symbol goes out of scope the data will still be accessible through the global symbol. This is perfectly legitimate and cannot be compared to the terrible mistake of taking a pointer to an automatic C variable and returning it from a function--when the pointer is dereferenced there will be a segmentation fault. (Note for C/C++ programmers: having a function return a pointer to an auto variable is a disaster in C or C++; the perl equivalent, returning a reference to a lexical variable created in a function is normal and useful.)
So while a my() scoped variable is called local, it's actually more like a reference/pointer to a dynamic object on the heap. You can pass it out of function safely.

Also in your explanation, I think you misinterpreted the "trailing scope" to apply to outside references, when it applies to the local variable. But reading into the documentation is somewhat bewildering. I get it, and at the same time I don't. ;)
 

notfred

Lifer
Feb 12, 2001
38,241
4
0
variables declared w/ 'my' go out of scope at the end of the block they were created in.

i.e.:

{
my $var;
} #<- $var goes out of scope.

{
my $foo;
for $stuff(@array){
my $i;
}#<- $i goes out of scope
}#<- $foo goes out of scope.

variables inside subroutines like this:

sub routine{
my $bar;
}

will expire at the end of execution of the subroutine.

Is that what you're asking? I don't know much about SQL, but I know quite a bit about perl.