Re: Question about Apache::Request and query strings
Tom Gazzini wrote: I have a perl function which, amongst other things, needs to redirect the request to another page. It also needs to pass all the query parameters of the original request (both GET and POST) to the redirected page, and also add one parameter of it's own (an error message). Sounds simple enough, but I'm having problems with the passing paramters bit. Here's what I have: sub show_error { my ($r, $error) = @_; # $r is an Apache:Request object passed by the caller my $uri = URI-new($url); foreach my $p (@params) { $uri-query_form($p = $r-param($p)); } $uri-query_form(error = $error); $r-internal_redirect($uri-canonical); } But this doesn't work. The '?error=' query string gets passed, but the orginal request query strings don't. What am I doing wrong? And is there an easier way? This example may help: http://perl.apache.org/docs/1.0/guide/snippets.html#Reusing_Data_from_POST_request __ Stas BekmanJAm_pH -- Just Another mod_perl Hacker http://stason.org/ mod_perl Guide --- http://perl.apache.org mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com http://modperlbook.org http://apache.org http://ticketmaster.com
Re: Question about Apache::Request and query strings
Tom Where's @params coming from ? Are you sure it's not empty ? Swen |-+ | | Tom Gazzini| | | [EMAIL PROTECTED]| | | uk | | || | | 06/26/2003 04:42 | | | PM | | || |-+ --| | | | To: [EMAIL PROTECTED] | | cc: | | Subject: Question about Apache::Request and query strings | | | | | --| I have a perl function which, amongst other things, needs to redirect the request to another page. It also needs to pass all the query parameters of the original request (both GET and POST) to the redirected page, and also add one parameter of it's own (an error message). Sounds simple enough, but I'm having problems with the passing paramters bit. Here's what I have: sub show_error { my ($r, $error) = @_; # $r is an Apache:Request object passed by the caller my $uri = URI-new($url); foreach my $p (@params) { $uri-query_form($p = $r-param($p)); } $uri-query_form(error = $error); $r-internal_redirect($uri-canonical); } But this doesn't work. The '?error=' query string gets passed, but the orginal request query strings don't. What am I doing wrong? And is there an easier way? Thanks, Tom
Re: Query
George Valpak wrote: Sounds like you need 2 apaches, on separate physical servers - I agree, the proxy approach is your best choice, and it gives other performance benefits as well, described in the documentation. - Perrin
Re: Query
On Tue, 7 Jan 2003, Chandrasekhar R S wrote: Date: Tue, 7 Jan 2003 12:52:27 +0530 From: Chandrasekhar R S [EMAIL PROTECTED] To: [EMAIL PROTECTED] Subject: Query I am having a requirement as follows : I need to execute/interpret the perl requests away from mod_perl. Like, could mod_perl delegate the execution/interpretation of perl scripts to some other process. In the end, mod_perl would be used just to accept requests from the Web Server, but processing will be done elsewhere and response will be routed back through mod_perl. - rsr. Namaste, R S Chandrasekhar [EMAIL PROTECTED] ISD : 091-080-2052427 Telnet : 847-2427 Phone : 2052427 RSR, You can certainly do something like this, in many different ways. This *is* still Perl, you know. :-) You could use your mod_perl process to update a queue that's in a file or database table, then have another process (written in Perl or whatever) executed by a cron job to look at the queue and process the next job. The user could be given a token to associate with the job, then then check back later to get the results of the job. If you need it to be more immediate, then you'll have to get fancier. If it's a really long-running process you need to kick off, you'll need to take into account the dangers of forking your mod_perl process or having it wait around for the end of the job. Have you tried searching the archives for similar questions? Here's one place you can search: http://mathforum.org/discussions/epi-search/modperl.html Namaste, ky
RE: Query
Hello Ken, You gave me a glimmer of hope and enthusiasm. I have scanned through the recent postings on Mod Perl list in vain. I would like to know any such standalone servers that could process the perl requests offline (taking requests from a file or queue end). I definitely would like to get fancier as my requirement is immediate. Upon finding a server that could process the requests away from mod_perl, I most probably would modify mod_perl to communicate with the standalone servers via sockets (and maybe maintain persistence). many thanks rsr. -Original Message- From: Ken Y. Clark [mailto:[EMAIL PROTECTED]] Sent: Tuesday, January 07, 2003 9:02 PM To: Chandrasekhar R S Cc: [EMAIL PROTECTED] Subject: Re: Query On Tue, 7 Jan 2003, Chandrasekhar R S wrote: Date: Tue, 7 Jan 2003 12:52:27 +0530 From: Chandrasekhar R S [EMAIL PROTECTED] To: [EMAIL PROTECTED] Subject: Query I am having a requirement as follows : I need to execute/interpret the perl requests away from mod_perl. Like, could mod_perl delegate the execution/interpretation of perl scripts to some other process. In the end, mod_perl would be used just to accept requests from the Web Server, but processing will be done elsewhere and response will be routed back through mod_perl. - rsr. Namaste, R S Chandrasekhar [EMAIL PROTECTED] ISD : 091-080-2052427 Telnet : 847-2427 Phone : 2052427 RSR, You can certainly do something like this, in many different ways. This *is* still Perl, you know. :-) You could use your mod_perl process to update a queue that's in a file or database table, then have another process (written in Perl or whatever) executed by a cron job to look at the queue and process the next job. The user could be given a token to associate with the job, then then check back later to get the results of the job. If you need it to be more immediate, then you'll have to get fancier. If it's a really long-running process you need to kick off, you'll need to take into account the dangers of forking your mod_perl process or having it wait around for the end of the job. Have you tried searching the archives for similar questions? Here's one place you can search: http://mathforum.org/discussions/epi-search/modperl.html Namaste, ky
Re: Query
Chandrasekhar R S wrote: I am having a requirement as follows : I need to execute/interpret the perl requests away from mod_perl. Can you explain why you want to do this? Your stated requirement is already met by CGI, FastCGI, SpeedyCGI, and a bunch of other things, but we can't really recommend anything specific without more information. - Perrin
RE: Query
On Tue, 7 Jan 2003, Chandrasekhar R S wrote: Date: Tue, 7 Jan 2003 21:38:57 +0530 From: Chandrasekhar R S [EMAIL PROTECTED] To: 'Ken Y. Clark' [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Subject: RE: Query Hello Ken, You gave me a glimmer of hope and enthusiasm. I have scanned through the recent postings on Mod Perl list in vain. I would like to know any such standalone servers that could process the perl requests offline (taking requests from a file or queue end). I definitely would like to get fancier as my requirement is immediate. Upon finding a server that could process the requests away from mod_perl, I most probably would modify mod_perl to communicate with the standalone servers via sockets (and maybe maintain persistence). many thanks rsr. RSR, I really think you're making this harder than it is. As was pointed out by another poster, there's nothing about your problem as you've described it that requires mod_perl. A simple CGI script could take your user input, write something to a file or database, and return a job ID. A separate Perl script could be launched every 60 seconds by crond and inspect the file or database for new jobs, process them, and write the results to another file or update the table. The user could then check back later with the original job ID for the results. There's no need for you to look for a server that could process the requests away from mod_perl. There's nothing wrong with the standard toolset that Unix already provides. And I really don't understand why you want to use sockets. First just solve your problem using the simplest solutions. If you then find things aren't performing to your expectations, tweak. Remember: Premature optimization is the root of all evil (Hoare). That's just one of many ideas you could use given how little I actually know about your problem. As none of what we've talked about involves mod_perl, I suggest we end this thread. Best of luck, ky -Original Message- From: Ken Y. Clark [mailto:[EMAIL PROTECTED]] Sent: Tuesday, January 07, 2003 9:02 PM To: Chandrasekhar R S Cc: [EMAIL PROTECTED] Subject: Re: Query On Tue, 7 Jan 2003, Chandrasekhar R S wrote: Date: Tue, 7 Jan 2003 12:52:27 +0530 From: Chandrasekhar R S [EMAIL PROTECTED] To: [EMAIL PROTECTED] Subject: Query I am having a requirement as follows : I need to execute/interpret the perl requests away from mod_perl. Like, could mod_perl delegate the execution/interpretation of perl scripts to some other process. In the end, mod_perl would be used just to accept requests from the Web Server, but processing will be done elsewhere and response will be routed back through mod_perl. - rsr. Namaste, R S Chandrasekhar [EMAIL PROTECTED] ISD : 091-080-2052427 Telnet : 847-2427 Phone : 2052427 RSR, You can certainly do something like this, in many different ways. This *is* still Perl, you know. :-) You could use your mod_perl process to update a queue that's in a file or database table, then have another process (written in Perl or whatever) executed by a cron job to look at the queue and process the next job. The user could be given a token to associate with the job, then then check back later to get the results of the job. If you need it to be more immediate, then you'll have to get fancier. If it's a really long-running process you need to kick off, you'll need to take into account the dangers of forking your mod_perl process or having it wait around for the end of the job. Have you tried searching the archives for similar questions? Here's one place you can search: http://mathforum.org/discussions/epi-search/modperl.html Namaste, ky
Re: Query
I definitely would like to get fancier as my requirement is immediate. Upon finding a server that could process the requests away from mod_perl, I most probably would modify mod_perl to communicate with the standalone servers via sockets (and maybe maintain persistence). Don't. You might want to use SOAP::Lite instead and save some hassle. But then again as said on the list, if you don't tell us what your problem is you probably won't have much helpful information. Cheers, -- Building a better web - http://www.mkdoc.com/ - Jean-Michel Hiver [EMAIL PROTECTED] - +44 (0)114 255 8097 Homepage: http://www.webmatrix.net/
RE: Query
Dear All, Let me explain my scenario. We are having a secure OS and we plan to integrate mod_perl with the Apache webserver already available on the OS. Being a secure server, it mandates that none of the exec's be done on the server itself, as these potentially can be malicious. Hence we delegate the execution of perl scripts elsewhere. Hence, should I be able to integrate mod_perl to my secure web server, I still would need to receive perl requests through mod_perl only, but rather than executing the scripts there itself, I should instruct mod_perl to delegate the interpretation/execution of perl scripts to elsewhere. This being the requirement, I planned to proceed this way - 1. I would modify mod_perl code to forward a perl request to another standalone server. This I planned to do with sockets (rather than employing Queues, files etc.) since, I would need persistent connections to serve dynamic perl scripts. 2. I should look for a server that could communicate with mod_perl. This server would execute the perl scripts and return the response back to mod_perl. This I call the standalone server. I will probe all the suggestions you all had sent me. I shall look for at the POE mail lists. with thanks rsr. -Original Message- From: Perrin Harkins [mailto:[EMAIL PROTECTED]] Sent: Tuesday, January 07, 2003 10:08 PM To: [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Subject: Re: Query Chandrasekhar R S wrote: I am having a requirement as follows : I need to execute/interpret the perl requests away from mod_perl. Can you explain why you want to do this? Your stated requirement is already met by CGI, FastCGI, SpeedyCGI, and a bunch of other things, but we can't really recommend anything specific without more information. - Perrin
RE: Query
rsr, Sounds like you need 2 apaches, on separate physical servers - The front end is called thin, and does not have mod perl at all, since nothing will run there. It lives mainly to proxy the perl requests to the second apache (often called heavy) will live on an inside IP address only (eg. 192.168.x.x or as needed for your network). This one has your standard mod perl stuff and just executes the requests it receives. It doesn't need to know anything about the fact that its requests are coming and going via proxy at all. There is excellent documentation on apache.org about how to do this - I just learned how to do it myself a couple of weeks ago, although in my case both apaches live on the same machine. Basically, the secure thin server needs to support mod_rewrite and mod_proxy plus whatever else you need it to do. If this meets your needs (and it seems like it will) you do not need any socket level stuff at all which should make you very happy. Just build your perl code to do what you want it to do, and make it run on the inside only server. The this server can serve fixed html files, images, and so on, or you could proxy them from the other apache, or yet another apache on an inside machine if the secure machine is not even allowed to do that. HTH, GV At 11:34 AM 1/8/2003 +0530, Chandrasekhar R S wrote: Dear All, Let me explain my scenario. We are having a secure OS and we plan to integrate mod_perl with the Apache webserver already available on the OS. Being a secure server, it mandates that none of the exec's be done on the server itself, as these potentially can be malicious. Hence we delegate the execution of perl scripts elsewhere. Hence, should I be able to integrate mod_perl to my secure web server, I still would need to receive perl requests through mod_perl only, but rather than executing the scripts there itself, I should instruct mod_perl to delegate the interpretation/execution of perl scripts to elsewhere. This being the requirement, I planned to proceed this way - 1. I would modify mod_perl code to forward a perl request to another standalone server. This I planned to do with sockets (rather than employing Queues, files etc.) since, I would need persistent connections to serve dynamic perl scripts. 2. I should look for a server that could communicate with mod_perl. This server would execute the perl scripts and return the response back to mod_perl. This I call the standalone server. I will probe all the suggestions you all had sent me. I shall look for at the POE mail lists. with thanks rsr. -Original Message- From: Perrin Harkins [mailto:[EMAIL PROTECTED]] Sent: Tuesday, January 07, 2003 10:08 PM To: [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Subject: Re: Query Chandrasekhar R S wrote: I am having a requirement as follows : I need to execute/interpret the perl requests away from mod_perl. Can you explain why you want to do this? Your stated requirement is already met by CGI, FastCGI, SpeedyCGI, and a bunch of other things, but we can't really recommend anything specific without more information. - Perrin
RE: [OT] Query
I would like to know any such standalone servers that could process the perl requests offline (taking requests from a file or queue end). I definitely would like to get fancier as my requirement is immediate. Upon finding a server that could process the requests away from mod_perl, I most probably would modify mod_perl to communicate with the standalone servers via sockets (and maybe maintain persistence). Well, I had a need like this, and I wrote a standalone server that my mod_perl processes communicate with, using POE (http://poe.perl.org). My POE server has, among other features, a TCP line-based interface. I can test it with a simple telnet, or using netcat(1). It meets my needs, but be advised that this server itself had (has!) a pretty substantial development time investment involved as well... and that is aside from simply learning how to make things work in POE! However, by no means should you consider POE your only opportunity... there are any number of ways to write a server daemon that can communicate with another process via TCP or pipe or whatever. That being said, this thread is now completely aside from mod_perl, and I agree it should terminate. But if you decide to pursue POE, then I'll see you on the POE list! L8r, Rob
Query
I am having a requirement as follows : I need to execute/interpret the perl requests away from mod_perl. Like, could mod_perl delegate the execution/interpretation of perl scripts to some other process. In the end, mod_perl would be used just to accept requests from the Web Server, but processing will be done elsewhere and response will be routed back through mod_perl. - rsr. Namaste, R S Chandrasekhar [EMAIL PROTECTED] ISD : 091-080-2052427 Telnet : 847-2427 Phone : 2052427
path_info() query.
Hello all, This is perhaps an apahce uri translation problem but: I am having a path_info problem... Synopsis. Location / SetHandler perl-script PerlHandler Module /Location Module.pm returns $r-path_info() in html to client. url: 'www.host/' returns '/' url: 'www.host/debug' returns '' when I was expecting '/debug' Now I can get around this with $r-uri but want to make sure that I undestand what I don't understand. Thanks for any help. Wes Rev. FPCED(UK) y n=-09hu6+40563 2136+-*+96, 3.-/n*+963.h
Re: path_info() query.
hi, apache uses a simple technique for determining the path_info. it starts at your document root and looks for the directory you specified in your URI. it continues to go deeper in the directory structure until it encounters a directory(or file) that doesn't exist. when this happens the the path_info is set to rest of the URI (not including the last part which wasn't found!). so in your case apache looks for $DOCROOT/debug this doesn't exist (presumably) in your $DOCROOT. so the path_info is set to whatever is left, ie nothing! if you tried to request www.host/debug/foo the path_info would be /foo (without the /debug part) if you created a directory called debug inside you docroot and you tried the previous example then you path_info would be empty. i hope this doesn't confuse you a a lot! best regards, giorgos Wes Cravens wrote: Hello all, This is perhaps an apahce uri translation problem but: I am having a path_info problem... Synopsis. Location / SetHandler perl-script PerlHandler Module /Location Module.pm returns $r-path_info() in html to client. url: 'www.host/' returns '/' url: 'www.host/debug' returns '' when I was expecting '/debug' Now I can get around this with $r-uri but want to make sure that I undestand what I don't understand. Thanks for any help. Wes Rev. FPCED(UK) y n=-09hu6+40563 2136+-*+96, 3.-/n*+963.h
Re: path_info() query.
On Thu, 4 Jul 2002, Wes Cravens wrote: url: 'www.host/' returns '/' url: 'www.host/debug' returns '' when I was expecting '/debug' does a file or directory named 'debug' exist in your document root? If so, it's normal. It is also possible that you are doing an error I made many times :) You are just facing a 'silent' 404 error, because the correct way to add path info to your first example is url: 'www.host/index.html/' returns '/' assuming that index.html is in your DirectoryIndex directive. So when you invoke url www.host/ you are being redirected to www.host/index.html. Hope it helps. Ciao, Valerio Valerio Paolini, http://130.136.3.200/~paolini -- what is open-source about? Learn, and then give back
RE: path_info() query.
Ok... I can see this. The piece of the puzzle that I am missing is why it behaves differently for / than for /stuff. I have taken out the Directory / information. I would have thought that when Apache saw www.host/stuff and there was no 'physical' stuff than it would pass /stuff as path_info to the module from Location / ... PerlHandler Module /Location Why does it not do this for /? Thanks for the help, Wes -Original Message- From: giorgos zervas [mailto:[EMAIL PROTECTED]] Sent: 04 July 2002 15:28 To: Wes Cravens Cc: modperl Subject: Re: path_info() query. hi, apache uses a simple technique for determining the path_info. it starts at your document root and looks for the directory you specified in your URI. it continues to go deeper in the directory structure until it encounters a directory(or file) that doesn't exist. when this happens the the path_info is set to rest of the URI (not including the last part which wasn't found!). so in your case apache looks for $DOCROOT/debug this doesn't exist (presumably) in your $DOCROOT. so the path_info is set to whatever is left, ie nothing! if you tried to request www.host/debug/foo the path_info would be /foo (without the /debug part) if you created a directory called debug inside you docroot and you tried the previous example then you path_info would be empty. i hope this doesn't confuse you a a lot! best regards, giorgos Wes Cravens wrote: Hello all, This is perhaps an apahce uri translation problem but: I am having a path_info problem... Synopsis. Location / SetHandler perl-script PerlHandler Module /Location Module.pm returns $r-path_info() in html to client. url: 'www.host/' returns '/' url: 'www.host/debug' returns '' when I was expecting '/debug' Now I can get around this with $r-uri but want to make sure that I undestand what I don't understand. Thanks for any help. Wes Rev. FPCED(UK) y n=-09hu6+40563 2136+-*+96, 3.-/n*+963.h
Re: Memory query
In article [EMAIL PROTECTED], Perrin Harkins [EMAIL PROTECTED] wrote: If you actually want to free the memory, you need to undef it. The untie prevents it from persisting, but the memory stays allocated unless you undef. OK, I think I'm probably handling this properly then, after all. In a Registry script, I typically tie the hash to a package global, and pass a reference to that hash to any routines in my library modules. At the end of the script, the hash is untied and the package global undefed. Many thanks, Andrew. -- perl -MLWP::Simple -e 'getprint(http://www.article7.co.uk/res/japh.txt;);'
Memory query
Morning all, Forgive the naivete, but I'm having trouble wrapping my mind around the memory implications of using tied hashes, and I haven't found anything in the Camel book or the Guide to clarify the situation for me. A fair amount of my Registry scripts need to use code not unlike the following: use strict; use Fcntl; use MLDBM qw(DB_File Storable); [...] tie(my %hash, 'MLDBM', $filename, O_RDONLY, 0644) or die Denied $filename: $!\n; foreach my $item (keys %hash) { action(\%hash,$item); } untie %hash; I'm intrigued about the memory implications of this kind of construction where the MLDBM hash is potentially very large. In particular, I'm looking for reassurance that passing a reference to a hash doesn't copy the hash itself into memory in any way, and that the memory overhead is only as large as the largest $item. Similarly, if I was to use vars(%hash); and initialise the tied hash as a global, does this have a significant memory overhead? Does untie-ing the hash clear the hash contents from memory, or do I also need to undef the hash to avoid the hash contents persisting from one request to the next? Is one approach better than the other? As I said, my apologies for the newbieness of all this, and even bigger apologies if it represents an FAQ that I've missed spotting. Many thanks, Andrew. -- perl -MLWP::Simple -e 'getprint(http://www.article7.co.uk/res/japh.txt;);'
query
The we are not able to bring the site up and running on linux version 6.2 with perl 5.005 , mod_perl 1.21 , I think the problem is the version of the perl that we are using . We have installed perl 5.6 but we are not able to figure out how to instruct apache to use that version of perl(5.6) .Are there any configuration parameter that could be changed . Is the our directive used in some of files new to perl 5.6 because we could not find that directive in the most of the perl books we referered to.
Re: query
Parag R Naik wrote: We have installed perl 5.6 but we are not able to figure out how to instruct apache to use that version of perl(5.6 You have to re-compile mod_perl. Is the our directive used in some of files new to perl 5.6 because we could not find that directive in the most of the perl books we referered to. Yes, it is new in 5.6. The most recent version of the camel book describes it, and so do the man pages. - Perrin
Re: Memory query
Andrew Green wrote: In particular, I'm looking for reassurance that passing a reference to a hash doesn't copy the hash itself into memory in any way, and that the memory overhead is only as large as the largest $item. That's basically correct, but some dbm implementations will use their own caching and that may increase this overhead. Similarly, if I was to use vars(%hash); and initialise the tied hash as a global, does this have a significant memory overhead? No, it's the same except for the addition of an entry in the symbol table. Does untie-ing the hash clear the hash contents from memory, or do I also need to undef the hash to avoid the hash contents persisting from one request to the next? If you actually want to free the memory, you need to undef it. The untie prevents it from persisting, but the memory stays allocated unless you undef. Is one approach better than the other? Not in terms of memory. The thing you need to think about with regard to dbm files is how to make sure they are synchronized between multiple processes. You basically just need to untie them after each request (unless it's read-only data). By the way, MLDBM::Sync takes care of all of that for you. - Perrin
Re: query
Hi there, On Wed, 13 Mar 2002, Parag R Naik wrote: We have installed perl 5.6 Make sure you get 5.6.1 not 5.6.0 which is buggy. 73, Ged.
Re: Very[OT]:Technical query re: scratchpad lookups for my() vars
Paul writes: --- Brian Ingerson [EMAIL PROTECTED] wrote: Garrett Goebel wrote: From: Paul [mailto:[EMAIL PROTECTED]] Anybody know offhand *why* my() lexicals are supposedly faster? Yes this is OT, but I'll contribute to the problem as well... My coworker Gisle Aas (maybe you've heard of him ;) says that globals and lexicals have identical speed because Perl optimizes out the symbol-table lookup. Trust Gisle. lol -- now *there's* an answer. So for my details I should go to the parse tree docs, and the code, I'm thinking. BTW -- with many thanks to everyone -- my question was "why are they faster", but the reason was never the speed -- it was to understand the way Perl stores and *accesses* lexicals. Any input? =o) If you have a reasonably recent Perl, you can do the following: % perl -MO=Terse,exec -e '$f = 123' OP (0x8180688) enter COP (0x8180628) nextstate SVOP (0x8175298) const IV (0x80f8770) 123 SVOP (0x817b488) gvsv GV (0x81017b0) *f BINOP (0x8180600) sassign LISTOP (0x8180660) leave % perl -MO=Terse,exec -e 'my $f = 123' OP (0x81805d0) enter COP (0x8180598) nextstate SVOP (0x8104b88) const IV (0x8104c9c) 123 OP (0x817b490) padsv [1] BINOP (0x81761f0) sassign LISTOP (0x81752a0) leave As you can see from the output, for a non-lexical $f, Perl uses an opcode "gvsv GV *f". The gvsv instruction gets a pointer to the entire glob (*f) from which it dereferences the SV (scalar) part and pushes it on the stack. See pp_hot.c: PP(pp_gvsv) { djSP; EXTEND(SP,1); if (PL_op-op_private OPpLVAL_INTRO) PUSHs(save_scalar(cGVOP_gv)); else PUSHs(GvSV(cGVOP_gv)); RETURN; } For the lexical, Perl has already determined at compile time that $f is in pad slot number 1 (think stack or register allocation). padsv is: PP(pp_padsv) { djSP; dTARGET; XPUSHs(TARG); ... If you navigate all the macros, you'll find that takes curpad (a pointer to an array of SV pointers: the current "stack frame" where "stack" is in the sense of a traditional compiler, not the (main) Perl stack) and pushes curpad[1] (remember $f was allocated slot 1 at compile time) onto the (main Perl) stack. --Malcolm -- Malcolm Beattie [EMAIL PROTECTED] Unix Systems Programmer Oxford University Computing Services
Re: Very[OT]:Technical query re: scratchpad lookups for my() vars
Paul wrote: --- Robert Landrum [EMAIL PROTECTED] wrote: I could be wrong, but as I recall, when your program enters a scope, perl immediatly identifies the the scratchpad to use. Then, it need only search backwards up the tree of scratchpads to find the variable "$x", which is faster than iterating through the STHASH looking for a localized or global $x. But how does it locate x in the scratchpad? Where're the docs? Or am I gonna have to read the code? =lol! Chapter 20 in "Advanced Perl programming"
Re: Very[OT]:Technical query re: scratchpad lookups for my() vars
Many thanks to everyone, Malcolm in particular, for humoring my curiosity and assisting my esoteric research. Hope it helped someone else, too, and sorry for cluttering up the board. But it *dod* say it was Very[OT]. ;o) Paul --- Malcolm Beattie [EMAIL PROTECTED] wrote: Paul writes: --- Brian Ingerson [EMAIL PROTECTED] wrote: Garrett Goebel wrote: From: Paul [mailto:[EMAIL PROTECTED]] Anybody know offhand *why* my() lexicals are supposedly faster? Yes this is OT, but I'll contribute to the problem as well... My coworker Gisle Aas (maybe you've heard of him ;) says that globals and lexicals have identical speed because Perl optimizes out the symbol-table lookup. Trust Gisle. lol -- now *there's* an answer. So for my details I should go to the parse tree docs, and the code, I'm thinking. BTW -- with many thanks to everyone -- my question was "why are they faster", but the reason was never the speed -- it was to understand the way Perl stores and *accesses* lexicals. Any input? =o) If you have a reasonably recent Perl, you can do the following: % perl -MO=Terse,exec -e '$f = 123' OP (0x8180688) enter COP (0x8180628) nextstate SVOP (0x8175298) const IV (0x80f8770) 123 SVOP (0x817b488) gvsv GV (0x81017b0) *f BINOP (0x8180600) sassign LISTOP (0x8180660) leave % perl -MO=Terse,exec -e 'my $f = 123' OP (0x81805d0) enter COP (0x8180598) nextstate SVOP (0x8104b88) const IV (0x8104c9c) 123 OP (0x817b490) padsv [1] BINOP (0x81761f0) sassign LISTOP (0x81752a0) leave As you can see from the output, for a non-lexical $f, Perl uses an opcode "gvsv GV *f". The gvsv instruction gets a pointer to the entire glob (*f) from which it dereferences the SV (scalar) part and pushes it on the stack. See pp_hot.c: PP(pp_gvsv) { djSP; EXTEND(SP,1); if (PL_op-op_private OPpLVAL_INTRO) PUSHs(save_scalar(cGVOP_gv)); else PUSHs(GvSV(cGVOP_gv)); RETURN; } For the lexical, Perl has already determined at compile time that $f is in pad slot number 1 (think stack or register allocation). padsv is: PP(pp_padsv) { djSP; dTARGET; XPUSHs(TARG); ... If you navigate all the macros, you'll find that takes curpad (a pointer to an array of SV pointers: the current "stack frame" where "stack" is in the sense of a traditional compiler, not the (main) Perl stack) and pushes curpad[1] (remember $f was allocated slot 1 at compile time) onto the (main Perl) stack. --Malcolm -- Malcolm Beattie [EMAIL PROTECTED] Unix Systems Programmer Oxford University Computing Services __ Do You Yahoo!? Yahoo! Auctions - Buy the things you want at great prices. http://auctions.yahoo.com/
RE: Very[OT]:Technical query re: scratchpad lookups for my() vars
Title: RE: Very[OT]:Technical query re: scratchpad lookups for my() vars From: Paul [mailto:[EMAIL PROTECTED]] Anybody know offhand *why* my() lexicals are supposedly faster? Because a dynamic variable allocates a new value at runtime which occludes the global value until it's scope expires. In contrast, a lexical variable is unique to its code value's (CV) context which was determined at parse time. However, if you recursively call that CV, then Perl has to allocate a new value for the lexical. Urban legend says that lexicals are on average 10% faster than dynamic variables. I wonder if that is true... and what difference recursion makes. I wonder how you'd write a script to benchmark that and actually benchmark the right thing...
Re: Very[OT]:Technical query re: scratchpad lookups for my() vars
Garrett Goebel wrote: From: Paul [mailto:[EMAIL PROTECTED]] Anybody know offhand *why* my() lexicals are supposedly faster? Because a dynamic variable allocates a "new" value at runtime which occludes the global value until it's scope expires. In contrast, a lexical variable is unique to its code value's (CV) context which was determined at parse time. However, if you recursively call that CV, then Perl has to allocate a new value for the lexical. Urban legend says that lexicals are on average 10% faster than dynamic variables. I wonder if that is true... and what difference recursion makes. I wonder how you'd write a script to benchmark that and actually benchmark the right thing... Yes this is OT, but I'll contribute to the problem as well... My coworker Gisle Aas (maybe you've heard of him ;) says that globals and lexicals have identical speed because Perl optimizes out the symbol-table lookup. Trust Gisle. -- perl -le 'use Inline C=q{SV*JAxH(char*x){return newSVpvf ("Just Another %s Hacker",x);}};print JAxH+Perl'
Very[OT]:Technical query re: scratchpad lookups for my() vars
Anybody know offhand *why* my() lexicals are supposedly faster? If they're stored on a scratchpad for the scope, which is an array, (technically a stack of them to accommodate recursion,) then exactly how does Perl go about finding which data location you mean when you say $x for a lexical? $::x has to go through the package lookup, which (if I recall correctly) is technically a hash element of a hash element at least..but if the scratchpad has a lot of scope-specific lexicals, how does it find which one is x? my $brain = 'tapioca'; #=o) __ Do You Yahoo!? Yahoo! Auctions - Buy the things you want at great prices. http://auctions.yahoo.com/
Re: Very[OT]:Technical query re: scratchpad lookups for my() vars
--- Robert Landrum [EMAIL PROTECTED] wrote: I could be wrong, but as I recall, when your program enters a scope, perl immediatly identifies the the scratchpad to use. Then, it need only search backwards up the tree of scratchpads to find the variable "$x", which is faster than iterating through the STHASH looking for a localized or global $x. But how does it locate x in the scratchpad? Where're the docs? Or am I gonna have to read the code? =lol! I think Mark-Jason Dominus has much more indepth look at the perl internals on his website... plover.com Great articles, read them today. Learned a new trick: my $fh = do { local *FH; }; But nothing about the structural/algorithmic mechanics. : __ Do You Yahoo!? Yahoo! Auctions - Buy the things you want at great prices. http://auctions.yahoo.com/
Re: Very[OT]:Technical query re: scratchpad lookups for my() vars
At 03:52 PM 3/14/01 -0800, Paul wrote: But nothing about the structural/algorithmic mechanics. : From the perlsub docs: Variables declared with my are not part of any package and are therefore never fully qualified with the package name. In particular, you're not allowed to try to make a package variable (or other global) lexical: my $pack::var; # ERROR! Illegal syntax my $_; # also illegal (currently) In fact, a dynamic variable (also known as package or global variables) are still accessible using the fully qualified :: notation even while a lexical of the same name is also visible: package main; local $x = 10; my$x = 20; print "$x and $::x\n"; That will print out 20 and 10. There is _no_ stash of lexicals during execution, only during compilation. I guess one of the reasons lexicals are faster. Elizabeth Mattijsen
Re: Very[OT]:Technical query re: scratchpad lookups for my() vars
--- Elizabeth Mattijsen [EMAIL PROTECTED] wrote: At 03:52 PM 3/14/01 -0800, Paul wrote: But nothing about the structural/algorithmic mechanics. : From the perlsub docs: Variables declared with my are not part of any package and are therefore never fully qualified with the package name. In particular, you're not allowed to try to make a package variable (or other global) lexical: my $pack::var; # ERROR! Illegal syntax my $_; # also illegal (currently) In fact, a dynamic variable (also known as package or global variables) are still accessible using the fully qualified :: notation even while a lexical of the same name is also visible: package main; local $x = 10; my$x = 20; print "$x and $::x\n"; That will print out 20 and 10. There is _no_ stash of lexicals during execution, only during compilation. I guess one of the reasons lexicals are faster. Elizabeth Mattijsen An excellent example, all known and understood. What I can't find is this: I know that my($x) puts x on this scope's scratchpad (and not in any package space), but rather than a hash named main:: with a key named x (which is, as I understand it, an oversimplification perhaps, but basically what Perl does internally for $main::x), exactly *how* does Perl "put" x into the scratchpad AV*? and once it's there, what did it store? How does it know that entry is 'x'? is it just a reference to the actual value? None of this is critical for anything I'm doing right now, but I'm a detail hound. I want to *understand* it, so that in the future I can make intelligent decisions about what would be a "better" way to write any given algorithm, without just relying on popular wisdom and "urban legend". =o) (That's why I said it was Very[OT], lol) Paul __ Do You Yahoo!? Yahoo! Auctions - Buy the things you want at great prices. http://auctions.yahoo.com/
$query-path+info is not what i thought it would be
Hi, could someone PLEASE help! I am trying to write a script that if accessed through http://server/script/ would produce HTML, where-as: http://server/script/wap/ would produce WML. That all worked fine until i converted to mod_perl. I did change $ENV{'PATH_INFO'} to the $query-path_info() code and usually works fine until there are multiple requests between wap and html. from what i can tell if you access the script with /wap/ it always works, but it's when you pass it nothing that I get what seems to be the contents of the Environment String of PATH_INFO which as it happens is the last document requested and would sometimes be /wap/. I have Apache 1.3.19, mod_perl 1.25, and activeperl 5.6.1 Could someone please tell me if this is a problem with mod perl, or the CGI module. Thanks Andrew -- Andrew Clark _ Do You Yahoo!? Get your free @yahoo.com address at http://mail.yahoo.com
Re: $query-path+info is not what i thought it would be
On Sat, 3 Mar 2001, Andrew Clark wrote: Hi, could someone PLEASE help! I am trying to write a script that if accessed through http://server/script/ would produce HTML, where-as: http://server/script/wap/ would produce WML. That all worked fine until i converted to mod_perl. I did change $ENV{'PATH_INFO'} to the $query-path_info() code and usually works fine until there are multiple requests between wap and html. from what i can tell if you access the script with /wap/ it always works, but it's when you pass it nothing that I get what seems to be the contents of the Environment String of PATH_INFO which as it happens is the last document requested and would sometimes be /wap/. Try http://take23.org/docs/guide/porting.xml/4#4 -- Matt/ /||** Founder and CTO ** ** http://axkit.com/ ** //||** AxKit.com Ltd ** ** XML Application Serving ** // ||** http://axkit.org ** ** XSLT, XPathScript, XSP ** // \\| // ** mod_perl news and resources: http://take23.org ** \\// //\\ // \\
Re: $query-path+info is not what i thought it would be
Thanks but it's nothing to do with global variables I don't think eg. my $query = new CGI; print $query-path_info(); works when a path info has been added to the URL but returns random results when there isn't one. Andrew In message [EMAIL PROTECTED], Matt Sergeant [EMAIL PROTECTED] writes On Sat, 3 Mar 2001, Andrew Clark wrote: Hi, could someone PLEASE help! I am trying to write a script that if accessed through http://server/script/ would produce HTML, where-as: http://server/script/wap/ would produce WML. That all worked fine until i converted to mod_perl. I did change $ENV{'PATH_INFO'} to the $query-path_info() code and usually works fine until there are multiple requests between wap and html. from what i can tell if you access the script with /wap/ it always works, but it's when you pass it nothing that I get what seems to be the contents of the Environment String of PATH_INFO which as it happens is the last document requested and would sometimes be /wap/. Try http://take23.org/docs/guide/porting.xml/4#4 -- Andrew Clark _ Do You Yahoo!? Get your free @yahoo.com address at http://mail.yahoo.com
A query regarding the common Parser
Hi all , I need to parse different url's to get the details of the medical sites and put it into my database and generate the newsite , I am using perl for getting the pages and parsing the data in all the pages and this seems to be semi manual kinda stuff, i need to see the page and then write the parser can anybody suggests any better way thanks and regards Rajesh Mathachan -- QuantumLink Communications, Bombay, India
Re: changing query string
Vincent Apesa ([EMAIL PROTECTED]) said something to this effect on 01/23/2001: Hello all, I'm trying to modify the query string from the client before sending it off again. I would like to do something like so: http://www.xyz.com?one=1 and modify the uri to http://www.xyz.com?one=2 the problem is I'm not sure how to reference values in the query string. I would like to be able to say queryArgs( 'one' ) = 2; This looks like a problem for mod_rewrite, if you have it compiled into your httpd. Do something like: RewriteEngine On RewriteCond %{QUERY_STRING} one=.* RewriteRule ^/$ http://www.xyz.com/?one=2 [R] (darren) -- There is no expedient to which a man will not go to avoid the real labour of thinking.
changing query string
Hello all, I'm trying to modify the query string from the client before sending it off again. I would like to do something like so: http://www.xyz.com?one=1 and modify the uri to http://www.xyz.com?one=2 the problem is I'm not sure how to reference values in the query string. I would like to be able to say queryArgs( 'one' ) = 2; Is there something in place to do this or should I parse the query string myself? Can someone point me in the right direction? thanks Vince
setting query in PerlTransHandler
This maybe be repeated becuase I sent the first message via Geo Crawlere and don't know how long they are going to take to review the message. Sorry if it comes in twice. I am writing a simple PerlTransHandler that is going to change the request into another with query string. The following is what I am looking for /articles/10/index.html = /articles/index.html?id=10 This is what I tried. sub handler { my $r = shift; my $uri = $r-uri; my ($id) = ($uri =~ m|^/articles/(.*?)/|); my $newuri = $r-document_root . "/articles/index.html"; my $uriobj = $r-parsed_uri; $uriobj-query("id=$id"); $r-uri($newuri); return OK; } 1; All .html documents are being parsed by Embperl and that works fine. In my document $fdat{id} doesn't return anything as I think it should be returing 10. printing out Apache-request-parsed_uri-query in the Embperl document doesn't print anything. In the book there only one sentece about using the query() method. and even that doesn't explain how to set up key=value to return it later. Any help is appreciated. Ajay __ Get Your Private, Free Email at http://www.hotmail.com
setting query in TransHandler
This message was sent from Geocrawler.com by "Ajay Shah" [EMAIL PROTECTED] Be sure to reply to that address. Hello list, This is my first post so bear with me. I am trying to write a simple PerlTransHandler that is going to modify the uri into something. I want to modify the following /articles/10/index.html = /articles/index.html?id=10 So this is my attempt: ... my ($id) = ($uri =~ m|^/articles/(.*?)/|); my $newuri = $r-document_root . "/articles/index.html"; my $uriobj = $r-parsed_uri; $uriobj-query("id=$id"); $r-uri($newuri); return OK; ... All .html files are parsed by Embperl and that works fine. What doesnt work is the $fdat{id} doesn't give me the id that was set.. printing out Apache-request-parsed_uri-query inside the index.html file doesn't give back anything.. I also tried to set the query string directly $r-uri("$newuri?id=$id"); but that didn't work either. any help or suggestions are welcomed. the book only has one sentecne on using the query() method. thanks. Ajay Geocrawler.com - The Knowledge Archive
Re: setting query in PerlTransHandler
"Ajay" == Ajay Shah [EMAIL PROTECTED] writes: Ajay /articles/10/index.html = /articles/index.html?id=10 Ajay This is what I tried. Ajay sub handler { Ajay my $r = shift; Ajay my $uri = $r-uri; Ajay my ($id) = ($uri =~ m|^/articles/(.*?)/|); Ajay my $newuri = $r-document_root . "/articles/index.html"; Ajay my $uriobj = $r-parsed_uri; Ajay $uriobj-query("id=$id"); Ajay $r-uri($newuri); Ajay return OK; Ajay } I may be wrong, but I bet you have to do this instead: $r-uri("/articles/index.html"); $r-args("id=$id"); By the time the apache-request object has been created, args are handled in a separate slot. -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 [EMAIL PROTECTED] 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!
trouble reading query string
i'm currently converting several CGI scripts into mod_perl modules, and i'm having difficulty in one particular situation reading the variable input (i.e., query string on a GET or STDIN on POST). quick background: i had a PerlHandler on the end of this request for a while, accepting input like "/foo?arg1=xarg2=y" which would create a form w/posted data (including binary info like .png, .gif, .jpg, and .mp3), save that data and return a user to a location. that was in the early stages of developing this. i'm now incorporating a more realistic shell around my dynamic output, one that show our ads which are proxy calls to a netscape ad server. my solution was to create a basic HTML page that has a simple perl sub on it, like so: !--File: foo.shtml -- html head title My Dynamic Page /title /head body !--#AD CALL -- !--#perl sub="Foo::Bar" -- !--#MORE AD CALLS -- /body /html a user gets to this page by clicking on a link like this: "/foo.shtml?arg1=xarg2=y". my module starts off like this: my $r = shift; $r = $r-is_main ? $r : $r-main; my %args = ($r-method_number == M_GET) ? $r-args : $r-content; but when i went from having the PerlHandler doing everything to having the module being called like an SSI call, %args doesn't get populated anymore. so i tried a hack i've done before with CGI.pm, like this: unless (%args) { my $q = CGI-new; my @names = $q-param; $args{$_} = $q-param($_) for @names; } but now, even this doesn't work, so i've had to put one more hack in, like this: unless (%args) { my $original_request = $r-the_request; my ($query_string) = ($original_request =~ m/\?(.*?)\s+HTTP.*/); my $q = CGI-new($query_string); my @names = $q-param; $args{$_} = $q-param($_) for @names; } so it now works, but i feel kinda dirty. and here's the last bit of strangeness: i have another page that is generated in the same manner that works just fine. the only difference is that the perl sub generates a form that is *not* enctype="multipart/form-data". both forms do, however, POST their data. any ideas why things are behaving so strangely? is my hack as objectionable as i think it is? ky
Re: trouble reading query string
At 11:52 AM 12/22/99 , Ken Y. Clark wrote: so it now works, but i feel kinda dirty. and here's the last bit of strangeness: i have another page that is generated in the same manner that works just fine. the only difference is that the perl sub generates a form that is *not* enctype="multipart/form-data". both forms do, however, POST their data. I'm not sure if I completely understand the problem at hand, but part of it, I think, is in trying to use $r-content with multipart/form-data data encoding. $r-content only works with application/x-www-form-urlencoded data (see the documentation for Apache.pm). To retrieve POSTed data in a multipart format you need to use $r-read or Apache::Request (see the docs for details). Cheers Dmitry
Re: Read query string on POST request?
On Thu, 16 Dec 1999, Tobias Hoellrich wrote: I pass a session id in the query string between invocations for my current project (only if the client does not support Cookies). My main handler is also responsible for creating an Apache::Request object right at the beginnig of the handler invocation. sub components rely on the information found in the $apr object. For GET's everything is fine, for POSTs the Apache::Request-new will not look at the query string, because it is a POST. Fine. that's strange, it's supposed to parse both, see apache_request.c : int ApacheRequest_parse_urlencoded(ApacheRequest *req) { request_rec *r = req-r; int rc = OK; if (r-method_number == M_POST) { ... parse POST body ... } if (r-args) { ... parse query string ... } return OK; } do you have a tiny case I can try?
Query/Parse/Format/Display ?
hi, I want to make the following : 1. Query a site ? 2. Get the results of the query in my script (we are still in Apache) 3. Exctract the information I need ? 4. Fomat it and send to the browser ? Does someone made something similar. Example ? Thanx in advance = iVAN [EMAIL PROTECTED] ==
RE: Query/Parse/Format/Display ?
Hi. You can use the get() method of LWP:Simple or the LWP:UserAgent, HTTP:Request and HTTP:Response methods. Both ways of doing it are described on recipe 20.1 of O'Reilly's "Perl Cookbook" (Tom Christiansen and Nathan Torkington). good luck ./ricarDo oliveiRa --Original Message-- From: raptor [EMAIL PROTECTED] To: [EMAIL PROTECTED][EMAIL PROTECTED] Sent: December 2, 1999 8:47:35 PM GMT Subject: Query/Parse/Format/Display ? hi, I want to make the following : 1. Query a site ? 2. Get the results of the query in my script (we are still in Apache) 3. Exctract the information I need ? 4. Fomat it and send to the browser ? Does someone made something similar. Example ? Thanx in advance = iVAN [EMAIL PROTECTED] == __ FREE Email for ALL! Sign up at http://www.mail.com
Performance query of DBD::Proxy
I guess this isn't exactly the right place, but if anyone knows about the real world and DBD::Proxy with Apache it's you people... I have been working with a client who has looked at using Intel platforms (with Linux cwas the initial alternative platform) as a backend modperl/Oracle web engine. They have been running on Solaris for years. As part of a related project they have used DBD::Proxy and DBI::ProxyServer to reach a "firewalled" DB. Hence the interest. I am curious if anyone has comments on the performance of using: DBD::Proxy - DBI::ProxyServer - DBD::Oracle - Oracle -- host1 -- host 2 -- -- host3 - or -- host1 -- -- host2 -- as opposed to DBD::Oracle - Oracle -- host1 -- -- host2 -- ? The reason is that at the moment their selection of base OS is dependent on having Oracle (or whatever) client libraries, and I would like to be able to widen their scope in terms of benchmarking with other OSes. Asking here is part of the first steps ... This solution, apart from offering a wider choice of platform, may also help focus resources and reliability issues on a functional / application software basis, rather than a very simple client-server model. (Even though both are client-server...) TIA. Regards, -- Peter Galbavy Knowledge Matters Ltd http://www.knowledge.com/