From nheller at silcon.com Sat Mar 1 17:32:32 2008 From: nheller at silcon.com (Neil Heller) Date: Sat, 1 Mar 2008 17:32:32 -0800 Subject: [sf-perl] CGI working In-Reply-To: <003a01c84674$5ebfd500$4301a8c0@Untangle.local> References: <003a01c84674$5ebfd500$4301a8c0@Untangle.local> Message-ID: <000f01c87c05$49a5c320$dcf14960$@com> I looked and looked unsuccessfully to directly find the answer to my question. I was hoping someone here knew off the top of his head. When a Perl-CGI program is launched, does it stay in memory as a singularity (like J2EE) or does it instantiate anew each time it's called? From friedman at highwire.stanford.edu Sat Mar 1 18:09:35 2008 From: friedman at highwire.stanford.edu (Michael Friedman) Date: Sat, 1 Mar 2008 18:09:35 -0800 Subject: [sf-perl] CGI working In-Reply-To: <000f01c87c05$49a5c320$dcf14960$@com> References: <003a01c84674$5ebfd500$4301a8c0@Untangle.local> <000f01c87c05$49a5c320$dcf14960$@com> Message-ID: If you are using mod_perl (or a similar setup for non-apache webservers) it will stay in memory between invocations. If you are just using CGI.pm and launching the program from a directory path, then it gets called anew each time. The CGI spec says that the webserver will call out to the program anew every time. That is the same no matter what language the program is written in: perl, python, C, bash shell, etc. It's a really expansive feature, since you can do anything you can do on the machine from the webserver, but it's a bit slow due to the repeated instantiations. ;-) You should check the documentation for your webserver about how it handles CGI scripts for further details. -- Mike On Mar 1, 2008, at 5:32 PM, Neil Heller wrote: > I looked and looked unsuccessfully to directly find the answer to my > question. I was hoping someone here knew off the top of his head. > > When a Perl-CGI program is launched, does it stay in memory as a > singularity > (like J2EE) or does it instantiate anew each time it's called? > > > > _______________________________________________ > SanFrancisco-pm mailing list > SanFrancisco-pm at pm.org > http://mail.pm.org/mailman/listinfo/sanfrancisco-pm --------------------------------------------------------------------- Michael Friedman HighWire Press Phone: 650-725-1974 Stanford University FAX: 270-721-8034 --------------------------------------------------------------------- From nheller at silcon.com Sat Mar 1 21:17:28 2008 From: nheller at silcon.com (Neil Heller) Date: Sat, 1 Mar 2008 21:17:28 -0800 Subject: [sf-perl] CGI working In-Reply-To: References: <003a01c84674$5ebfd500$4301a8c0@Untangle.local> <000f01c87c05$49a5c320$dcf14960$@com> Message-ID: <000001c87c24$b5a38ac0$20eaa040$@com> Are you saying that using plain Perl CGI programs in Apache means that the application (really the script, in this case) will NOT stay in memory between invocations? That's a bummer for me. Neil Heller -----Original Message----- From: sanfrancisco-pm-bounces+nheller=silcon.com at pm.org [mailto:sanfrancisco-pm-bounces+nheller=silcon.com at pm.org] On Behalf Of Michael Friedman Sent: Saturday, March 01, 2008 6:10 PM To: San Francisco Perl Mongers User Group Subject: Re: [sf-perl] CGI working If you are using mod_perl (or a similar setup for non-apache webservers) it will stay in memory between invocations. If you are just using CGI.pm and launching the program from a directory path, then it gets called anew each time. The CGI spec says that the webserver will call out to the program anew every time. That is the same no matter what language the program is written in: perl, python, C, bash shell, etc. It's a really expansive feature, since you can do anything you can do on the machine from the webserver, but it's a bit slow due to the repeated instantiations. ;-) You should check the documentation for your webserver about how it handles CGI scripts for further details. -- Mike On Mar 1, 2008, at 5:32 PM, Neil Heller wrote: > I looked and looked unsuccessfully to directly find the answer to my > question. I was hoping someone here knew off the top of his head. > > When a Perl-CGI program is launched, does it stay in memory as a > singularity > (like J2EE) or does it instantiate anew each time it's called? > > > > _______________________________________________ > SanFrancisco-pm mailing list > SanFrancisco-pm at pm.org > http://mail.pm.org/mailman/listinfo/sanfrancisco-pm --------------------------------------------------------------------- Michael Friedman HighWire Press Phone: 650-725-1974 Stanford University FAX: 270-721-8034 --------------------------------------------------------------------- _______________________________________________ SanFrancisco-pm mailing list SanFrancisco-pm at pm.org http://mail.pm.org/mailman/listinfo/sanfrancisco-pm From woof at danlo.com Sat Mar 1 21:39:42 2008 From: woof at danlo.com (Daniel Lo) Date: Sat, 1 Mar 2008 21:39:42 -0800 Subject: [sf-perl] CGI working In-Reply-To: <000001c87c24$b5a38ac0$20eaa040$@com> References: <003a01c84674$5ebfd500$4301a8c0@Untangle.local> <000f01c87c05$49a5c320$dcf14960$@com> <000001c87c24$b5a38ac0$20eaa040$@com> Message-ID: <1155995594.20080301213942@danlo.com> Hello Neil, Plain generic Perl CGI programs will not stay in memory between invocations. This is a plus in some regards. 1. Any attempts to affect the next invocation (hacking) will fail, because the program starts fresh. 2. No memory leaks (well, nothing you have to worry about). 3. It leaves memory! (If your application, is called once every 20 minutes, it is not hogging memory!) 4. Easier to debug. 5. Widely supported. (What server doesn't do this...) 6. If your program is called often, the harddisk sectors containing the program are likely to stay in the OS cache, so its not that painful) 7. Less problems (sometimes). You don't have issues with programs that run a long time. (Not giving up database connections, memory hogs, caching issues, un-initialized variables between calls, etc..) --- There are other ways around this. FastCGI (FastCGI.com) is a simple wrapper that is easy to use (FCGI.pm/CGI.pm). And there is mod_perl. You may want to check out Catalyst: http://catalyst.perl.org/ -daniel Saturday, March 1, 2008, 9:17:28 PM, you wrote: > Are you saying that using plain Perl CGI programs in Apache means that the > application (really the script, in this case) will NOT stay in memory > between invocations? That's a bummer for me. > Neil Heller > -----Original Message----- > From: sanfrancisco-pm-bounces+nheller=silcon.com at pm.org > [mailto:sanfrancisco-pm-bounces+nheller=silcon.com at pm.org] On Behalf Of > Michael Friedman > Sent: Saturday, March 01, 2008 6:10 PM > To: San Francisco Perl Mongers User Group > Subject: Re: [sf-perl] CGI working > If you are using mod_perl (or a similar setup for non-apache > webservers) it will stay in memory between invocations. If you are > just using CGI.pm and launching the program from a directory path, > then it gets called anew each time. > The CGI spec says that the webserver will call out to the program anew > every time. That is the same no matter what language the program is > written in: perl, python, C, bash shell, etc. It's a really expansive > feature, since you can do anything you can do on the machine from the > webserver, but it's a bit slow due to the repeated instantiations. ;-) > You should check the documentation for your webserver about how it > handles CGI scripts for further details. > -- Mike > On Mar 1, 2008, at 5:32 PM, Neil Heller wrote: >> I looked and looked unsuccessfully to directly find the answer to my >> question. I was hoping someone here knew off the top of his head. >> >> When a Perl-CGI program is launched, does it stay in memory as a >> singularity >> (like J2EE) or does it instantiate anew each time it's called? >> >> >> >> _______________________________________________ >> SanFrancisco-pm mailing list >> SanFrancisco-pm at pm.org >> http://mail.pm.org/mailman/listinfo/sanfrancisco-pm > --------------------------------------------------------------------- > Michael Friedman HighWire Press > Phone: 650-725-1974 Stanford University > FAX: 270-721-8034 > --------------------------------------------------------------------- > _______________________________________________ > SanFrancisco-pm mailing list > SanFrancisco-pm at pm.org > http://mail.pm.org/mailman/listinfo/sanfrancisco-pm > _______________________________________________ > SanFrancisco-pm mailing list > SanFrancisco-pm at pm.org > http://mail.pm.org/mailman/listinfo/sanfrancisco-pm -- Best regards, Daniel mailto:woof at danlo.com From darin_fisher at yahoo.com Sat Mar 1 21:48:37 2008 From: darin_fisher at yahoo.com (Darin Fisher) Date: Sat, 1 Mar 2008 21:48:37 -0800 (PST) Subject: [sf-perl] CGI working Message-ID: <863673.64477.qm@web35306.mail.mud.yahoo.com> Yes, put simply. It's not up to Perl, it's depend on the web server configuration not the application. -Darin Not a shred of evidence exists in favor of the idea that life is serious. - Brendan Gill ----- Original Message ---- From: Neil Heller To: San Francisco Perl Mongers User Group Sent: Saturday, March 1, 2008 9:17:28 PM Subject: Re: [sf-perl] CGI working Are you saying that using plain Perl CGI programs in Apache means that the application (really the script, in this case) will NOT stay in memory between invocations? That's a bummer for me. Neil Heller -----Original Message----- From: sanfrancisco-pm-bounces+nheller=silcon.com at pm.org [mailto:sanfrancisco-pm-bounces+nheller=silcon.com at pm.org] On Behalf Of Michael Friedman Sent: Saturday, March 01, 2008 6:10 PM To: San Francisco Perl Mongers User Group Subject: Re: [sf-perl] CGI working If you are using mod_perl (or a similar setup for non-apache webservers) it will stay in memory between invocations. If you are just using CGI.pm and launching the program from a directory path, then it gets called anew each time. The CGI spec says that the webserver will call out to the program anew every time. That is the same no matter what language the program is written in: perl, python, C, bash shell, etc. It's a really expansive feature, since you can do anything you can do on the machine from the webserver, but it's a bit slow due to the repeated instantiations. ;-) You should check the documentation for your webserver about how it handles CGI scripts for further details. -- Mike On Mar 1, 2008, at 5:32 PM, Neil Heller wrote: > I looked and looked unsuccessfully to directly find the answer to my > question. I was hoping someone here knew off the top of his head. > > When a Perl-CGI program is launched, does it stay in memory as a > singularity > (like J2EE) or does it instantiate anew each time it's called? > > > > _______________________________________________ > SanFrancisco-pm mailing list > SanFrancisco-pm at pm.org > http://mail.pm.org/mailman/listinfo/sanfrancisco-pm --------------------------------------------------------------------- Michael Friedman HighWire Press Phone: 650-725-1974 Stanford University FAX: 270-721-8034 --------------------------------------------------------------------- _______________________________________________ SanFrancisco-pm mailing list SanFrancisco-pm at pm.org http://mail.pm.org/mailman/listinfo/sanfrancisco-pm _______________________________________________ SanFrancisco-pm mailing list SanFrancisco-pm at pm.org http://mail.pm.org/mailman/listinfo/sanfrancisco-pm -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.pm.org/pipermail/sanfrancisco-pm/attachments/20080301/6aed59a3/attachment.html From quinn at fairpath.com Sun Mar 2 10:58:36 2008 From: quinn at fairpath.com (Quinn Weaver) Date: Sun, 2 Mar 2008 10:58:36 -0800 Subject: [sf-perl] CGI working In-Reply-To: <000001c87c24$b5a38ac0$20eaa040$@com> References: <003a01c84674$5ebfd500$4301a8c0@Untangle.local> <000f01c87c05$49a5c320$dcf14960$@com> <000001c87c24$b5a38ac0$20eaa040$@com> Message-ID: <20080302185835.GA85635@fu.funkspiel.org> On Sat, Mar 01, 2008 at 09:17:28PM -0800, Neil Heller wrote: > Are you saying that using plain Perl CGI programs in Apache means that the > application (really the script, in this case) will NOT stay in memory > between invocations? That's a bummer for me. Check Apache::Registry on CPAN. It lets you "[r]un unaltered CGI scrips under mod_perl." In general, it Just Works. But there are some subtle problems that can crop up, depending on how your CGI scripts are coded. The _mod_perl Developer's Cookbook_ has a longish section that explains these (chapter 2, section 2). In the meantime, your best bet is to use strict; and use warnings; in every CGI script (if you don't already). That will expose many of the problems right away. HTH, -- Quinn Weaver, independent contractor | President, San Francisco Perl Mongers http://fairpath.com/quinn/resume/ | http://sf.pm.org/ 510-520-5217 From david at fetter.org Sun Mar 2 11:04:47 2008 From: david at fetter.org (David Fetter) Date: Sun, 2 Mar 2008 11:04:47 -0800 Subject: [sf-perl] CGI working In-Reply-To: <20080302185835.GA85635@fu.funkspiel.org> References: <003a01c84674$5ebfd500$4301a8c0@Untangle.local> <000f01c87c05$49a5c320$dcf14960$@com> <000001c87c24$b5a38ac0$20eaa040$@com> <20080302185835.GA85635@fu.funkspiel.org> Message-ID: <20080302190447.GD10306@fetter.org> On Sun, Mar 02, 2008 at 10:58:36AM -0800, Quinn Weaver wrote: > On Sat, Mar 01, 2008 at 09:17:28PM -0800, Neil Heller wrote: > In the meantime, your best bet is to use strict; and use warnings; > in every CGI script (if you don't already). s/CGI script/Perl program/g; > That will expose many of the problems right away. ...as it will in all your other applications. :) Cheers, David. -- David Fetter http://fetter.org/ Phone: +1 415 235 3778 AIM: dfetter666 Yahoo!: dfetter Skype: davidfetter XMPP: david.fetter at gmail.com Remember to vote! Consider donating to Postgres: http://www.postgresql.org/about/donate From fred at redhotpenguin.com Sun Mar 2 11:47:50 2008 From: fred at redhotpenguin.com (Fred Moyer) Date: Sun, 2 Mar 2008 11:47:50 -0800 Subject: [sf-perl] CGI working In-Reply-To: <20080302185835.GA85635@fu.funkspiel.org> References: <003a01c84674$5ebfd500$4301a8c0@Untangle.local> <20080302185835.GA85635@fu.funkspiel.org> Message-ID: <1204487273.339E23F0@di12.dngr.org> On Sun, 2 Mar 2008 10:58 am, Quinn Weaver wrote: > On Sat, Mar 01, 2008 at 09:17:28PM -0800, Neil Heller wrote: >> Are you saying that using plain Perl CGI programs in Apache means >> that the >> application (really the script, in this case) will NOT stay in memory >> between invocations? That's a bummer for me. > > Check Apache::Registry on CPAN. It lets you "[r]un unaltered CGI > scrips under mod_perl." You can also check out http://us.apachecon.com/us2007/downloads/mod_perl-2.0-from-cgi-fast.pdf That talk has more details than you can swing an httpd process at :) From rdm at cfcl.com Sun Mar 2 14:24:36 2008 From: rdm at cfcl.com (Rich Morin) Date: Sun, 2 Mar 2008 14:24:36 -0800 Subject: [sf-perl] use {strict,warnings} Message-ID: "use {strict,warnings}" are indeed very comforting to have as a safety net for development. I have been speculating about ways to add similar (and perhaps stronger) tests to Ruby, using some form of metaprogramming. So, I'd like to hear folks' opinions on what kinds of tests they find most (and least :-) useful, what tests they'd like to have, how best to make them minimally annoying, etc. -r -- http://www.cfcl.com/rdm Rich Morin http://www.cfcl.com/rdm/resume rdm at cfcl.com http://www.cfcl.com/rdm/weblog +1 650-873-7841 Technical editing and writing, programming, and web development From david at fetter.org Sun Mar 2 15:27:35 2008 From: david at fetter.org (David Fetter) Date: Sun, 2 Mar 2008 15:27:35 -0800 Subject: [sf-perl] use {strict,warnings} In-Reply-To: References: Message-ID: <20080302232735.GC24586@fetter.org> On Sun, Mar 02, 2008 at 02:24:36PM -0800, Rich Morin wrote: > "use {strict,warnings}" are indeed very comforting to have as a > safety net for development. I have been speculating about ways to > add similar (and perhaps stronger) tests to Ruby, using some form of > metaprogramming. What a bummer for Ruby that it doesn't have this basic kind of protection...over ten years after perl got it. ;) > So, I'd like to hear folks' opinions on what kinds of tests they > find most (and least :-) useful, what tests they'd like to have, how > best to make them minimally annoying, etc. Tests, if you'll pardon the Rumsfeld-ism, are for known unknowns, and they frequently lead to a false sense of security. It's the unknown unknowns that come up and bite you on the butt. Cheers, David. -- David Fetter http://fetter.org/ Phone: +1 415 235 3778 AIM: dfetter666 Yahoo!: dfetter Skype: davidfetter XMPP: david.fetter at gmail.com Remember to vote! Consider donating to Postgres: http://www.postgresql.org/about/donate From quinn at fairpath.com Sun Mar 2 15:28:10 2008 From: quinn at fairpath.com (Quinn Weaver) Date: Sun, 2 Mar 2008 15:28:10 -0800 Subject: [sf-perl] use {strict,warnings} In-Reply-To: References: Message-ID: <20080302232810.GA86399@fu.funkspiel.org> On Sun, Mar 02, 2008 at 02:24:36PM -0800, Rich Morin wrote: > So, I'd like to hear folks' opinions on what kinds of tests they > find most (and least :-) useful, what tests they'd like to have, > how best to make them minimally annoying, etc. Most useful (paraphrased): - use of undefined variable (catches typos, among other things) - variable already defined (for instance, two my $var = statements in one scope) - couldn't find $package; did you remember to load $module? - no such method $foo (happens at runtime, unfortunately, due to late binding) - close called on an unopened filehandle Least useful: - Can't think of any. :) Best way to make them useful: - Wherever possible, make the analysis static. - If you can't do perfectly reliable static analysis, heuristics are still good. - Make some kind of prepackaged test target that runs your all your tests (or a chosen subset) and either flunks your program or gives it a clean bill of health. -- Quinn Weaver, independent contractor | President, San Francisco Perl Mongers http://fairpath.com/quinn/resume/ | http://sf.pm.org/ 510-520-5217 From quinn at fairpath.com Sun Mar 2 15:46:33 2008 From: quinn at fairpath.com (Quinn Weaver) Date: Sun, 2 Mar 2008 15:46:33 -0800 Subject: [sf-perl] use {strict,warnings} In-Reply-To: <20080302232735.GC24586@fetter.org> References: <20080302232735.GC24586@fetter.org> Message-ID: <20080302234633.GA86511@fu.funkspiel.org> On Sun, Mar 02, 2008 at 03:27:35PM -0800, David Fetter wrote: > Tests, if you'll pardon the Rumsfeld-ism, are for known unknowns, and > they frequently lead to a false sense of security. It's the unknown > unknowns that come up and bite you on the butt. True! OTOH, for mere mortals like me, just making clear one's assumptions about what the known behavior is supposed to be (and then having a way to verify that they this behavior isn't regressing) is a major boon. Of course, when you stumble across an unknown unknown, you fix the bug and write new a test case for it. Then you continue marching backwards into the future... -- Quinn Weaver, independent contractor | President, San Francisco Perl Mongers http://fairpath.com/quinn/resume/ | http://sf.pm.org/ 510-520-5217 From biztos at mac.com Sun Mar 2 15:49:32 2008 From: biztos at mac.com (Kevin Frost) Date: Sun, 2 Mar 2008 15:49:32 -0800 Subject: [sf-perl] use {strict,warnings} In-Reply-To: <20080302232810.GA86399@fu.funkspiel.org> References: <20080302232810.GA86399@fu.funkspiel.org> Message-ID: <07D10AFC-5221-42A8-8C79-2A3C962EEA13@mac.com> Most: Undef vars, vars used only once. Plus all the stuff I don't screw up anymore after years of strict warnings. Least: Use of uninitialized variables. I also catch lots of typos by habitually pertidying as I code. If my indentation suddenly gets thrown out of whack, command-Z and look for fat fingers. -- frosty (via iPhone) On Mar 2, 2008, at 3:28 PM, Quinn Weaver wrote: > On Sun, Mar 02, 2008 at 02:24:36PM -0800, Rich Morin wrote: > >> So, I'd like to hear folks' opinions on what kinds of tests they >> find most (and least :-) useful, what tests they'd like to have, >> how best to make them minimally annoying, etc. > > Most useful (paraphrased): > > - use of undefined variable (catches typos, among other things) > - variable already defined (for instance, two my $var = statements > in one scope) > - couldn't find $package; did you remember to load $module? > - no such method $foo (happens at runtime, unfortunately, due to > late binding) > - close called on an unopened filehandle > > Least useful: > > - Can't think of any. :) > > Best way to make them useful: > > - Wherever possible, make the analysis static. > - If you can't do perfectly reliable static analysis, heuristics are > still good. > - Make some kind of prepackaged test target that runs your all your > tests > (or a chosen subset) and either flunks your program or gives it a > clean > bill of health. > > -- > Quinn Weaver, independent contractor | President, San Francisco > Perl Mongers > http://fairpath.com/quinn/resume/ | http://sf.pm.org/ > 510-520-5217 > _______________________________________________ > SanFrancisco-pm mailing list > SanFrancisco-pm at pm.org > http://mail.pm.org/mailman/listinfo/sanfrancisco-pm From rdm at cfcl.com Sun Mar 2 15:51:59 2008 From: rdm at cfcl.com (Rich Morin) Date: Sun, 2 Mar 2008 15:51:59 -0800 Subject: [sf-perl] use {strict,warnings} In-Reply-To: <20080302232735.GC24586@fetter.org> References: <20080302232735.GC24586@fetter.org> Message-ID: DF> What a bummer for Ruby that it doesn't have this basic DF> kind of protection...over ten years after perl got it. ;) Fortunately, I can add features to Ruby via metaprogramming of various sorts, make them dynamically configurable, etc. And, in Rubinius, I can actually extend the interpreter to (say) collect more information as the script is being parsed. Unfortunately, all of this requires Real Work... DF> Tests, if you'll pardon the Rumsfeld-ism, are for known DF> unknowns, and they frequently lead to a false sense of DF> security. It's the unknown unknowns that come up and DF> bite you on the butt. Peculiarly, many in the Ruby camp use a similar argument to say that built-in tests (as provided by strict and warnings) are too low-level, so they don't catch semantic and design errors. "Just write appropriate tests." My take is certain types of errors are known to be common, so why not let the computer check for them? Of course, the tests should be optional, customizable, and dynamically configurable. FWIW, the Fortress type system has some interesting ideas. For example, it can keep you from calculating furlongs per fortnight and saving the result in a variable whose type is fortnights per furlong. I don't think I want to be required to specify things that tightly for much of my work, but when the code really has to work, this can provide useful checks. QW> - Wherever possible, make the analysis static. QW> QW> - If you can't do perfectly reliable static analysis, QW> heuristics are still good. QW> QW> - Make some kind of prepackaged test target that runs QW> all your tests (or a chosen subset) and either flunks QW> your program or gives it a clean bill of health. +1 -r -- http://www.cfcl.com/rdm Rich Morin http://www.cfcl.com/rdm/resume rdm at cfcl.com http://www.cfcl.com/rdm/weblog +1 650-873-7841 Technical editing and writing, programming, and web development From quinn at fairpath.com Sun Mar 2 16:13:24 2008 From: quinn at fairpath.com (Quinn Weaver) Date: Sun, 2 Mar 2008 16:13:24 -0800 Subject: [sf-perl] use {strict,warnings} In-Reply-To: <07D10AFC-5221-42A8-8C79-2A3C962EEA13@mac.com> References: <20080302232810.GA86399@fu.funkspiel.org> <07D10AFC-5221-42A8-8C79-2A3C962EEA13@mac.com> Message-ID: <20080303001324.GA86613@fu.funkspiel.org> On Sun, Mar 02, 2008 at 03:49:32PM -0800, Kevin Frost wrote: > Most: > > Undef vars, vars used only once. ^^^^^^^^^^^^^^^^^^^ I second that. Also useful: - Deep recursion - Read on closed filehandle (various) - Cannot call method on undef value - Various messages about string termination and quoting, runaway strings and regexes - Unknown Unicode chars (I guess) -- Quinn Weaver, independent contractor | President, San Francisco Perl Mongers http://fairpath.com/quinn/resume/ | http://sf.pm.org/ 510-520-5217 From david at fetter.org Sun Mar 2 16:29:44 2008 From: david at fetter.org (David Fetter) Date: Sun, 2 Mar 2008 16:29:44 -0800 Subject: [sf-perl] use {strict,warnings} In-Reply-To: <20080302234633.GA86511@fu.funkspiel.org> References: <20080302232735.GC24586@fetter.org> <20080302234633.GA86511@fu.funkspiel.org> Message-ID: <20080303002944.GD24586@fetter.org> On Sun, Mar 02, 2008 at 03:46:33PM -0800, Quinn Weaver wrote: > On Sun, Mar 02, 2008 at 03:27:35PM -0800, David Fetter wrote: > > > Tests, if you'll pardon the Rumsfeld-ism, are for known unknowns, > > and they frequently lead to a false sense of security. It's the > > unknown unknowns that come up and bite you on the butt. > > True! OTOH, for mere mortals like me, just making clear one's > assumptions about what the known behavior is supposed to be (and > then having a way to verify that they this behavior isn't > regressing) is a major boon. For people like me who are even more mortal, it's important, too. In an attempt to learn from past mistakes, I created this rule about Perl code, which is that strict and warnings are mandatory all the way through the code. I hope that this rule prevents me from doing things cleverly.[1] It's worked pretty well so far... > Of course, when you stumble across an unknown unknown, you fix the bug > and write new a test case for it. This isn't always a good idea. > Then you continue marching backwards into the future... It seems to me that people in our business need to cultivate mindfulness, if you'll allow me a little casual Zen, along with good habits. That combination makes for a very tricky path to walk. Cheers, David. [1] Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. Kernighan -- David Fetter http://fetter.org/ Phone: +1 415 235 3778 AIM: dfetter666 Yahoo!: dfetter Skype: davidfetter XMPP: david.fetter at gmail.com Remember to vote! Consider donating to Postgres: http://www.postgresql.org/about/donate From doom at kzsu.stanford.edu Sun Mar 2 23:57:45 2008 From: doom at kzsu.stanford.edu (Joe Brenner) Date: Sun, 02 Mar 2008 23:57:45 -0800 Subject: [sf-perl] use {strict,warnings} In-Reply-To: References: <20080302232735.GC24586@fetter.org> Message-ID: <200803030757.m237vjDL037371@kzsu.stanford.edu> Rich Morin wrote: > Peculiarly, many in the Ruby camp use a similar argument to > say that built-in tests (as provided by strict and warnings) > are too low-level, so they don't catch semantic and design > errors. "Just write appropriate tests." Ah. They used to be PHP programmers. From doom at kzsu.stanford.edu Mon Mar 3 00:44:13 2008 From: doom at kzsu.stanford.edu (Joe Brenner) Date: Mon, 03 Mar 2008 00:44:13 -0800 Subject: [sf-perl] use {strict,warnings} In-Reply-To: <07D10AFC-5221-42A8-8C79-2A3C962EEA13@mac.com> References: <20080302232810.GA86399@fu.funkspiel.org> <07D10AFC-5221-42A8-8C79-2A3C962EEA13@mac.com> Message-ID: <200803030844.m238iDWP037982@kzsu.stanford.edu> Kevin Frost wrote: > Least: > > Use of uninitialized variables. Yeah, that's a problematic one, isn't it? Perl will happily do type conversions for you, but (if used in the recommended way, with strict and warnings) it nags incessantly about undefs, rather than just treating them as empty strings. Though it could be, of course, that the constant need to dance around this to silence suprious "unit" warnings is cleaning up my code in ways I don't appreciate. From biztos at mac.com Mon Mar 3 03:43:56 2008 From: biztos at mac.com (frosty) Date: Mon, 03 Mar 2008 03:43:56 -0800 Subject: [sf-perl] use {strict,warnings} In-Reply-To: <200803030844.m238iDWP037982@kzsu.stanford.edu> References: <20080302232810.GA86399@fu.funkspiel.org> <07D10AFC-5221-42A8-8C79-2A3C962EEA13@mac.com> <200803030844.m238iDWP037982@kzsu.stanford.edu> Message-ID: I actually find it useful sometimes, but on average more annoying than useful. The useful thing is that it reminds me to be clearer in things like printing and logging: use strict; use warnings; my $nope = undef; printf "You set it to '%s'\n", $nope; # warns. printf "You set it to '%s'\n", $nope || 'UNDEF'; # better. But: my $stuff = join( "fee", "fi", "fo", $nope ); # warns, annoying (to me). die "$nope would be nice"; # warns, annoying (to me). On the one hand I wish undefined values could be auto-vivified to 'UNDEF' in warn and die, but on the other hand that's probably sqlplus poisoning my brain. The problem, I find, with disabling warnings is that my list of annoying warnings may not be the same as my colleague's list. That plus you have nobody to blame but yourself when you screw up. The problem with *not* doing that is there is plenty of CPAN code that spews warnings all over your log files if you happen to have any. -- f. On Monday, March 03, 2008, at 12:45AM, "Joe Brenner" wrote: > >Kevin Frost wrote: > >> Least: >> >> Use of uninitialized variables. > >Yeah, that's a problematic one, isn't it? Perl will happily do type >conversions for you, but (if used in the recommended way, with strict >and warnings) it nags incessantly about undefs, rather than just >treating them as empty strings. > >Though it could be, of course, that the constant need to dance around >this to silence suprious "unit" warnings is cleaning up my code in ways >I don't appreciate. > > >_______________________________________________ >SanFrancisco-pm mailing list >SanFrancisco-pm at pm.org >http://mail.pm.org/mailman/listinfo/sanfrancisco-pm > > From dat1965 at yahoo.com Mon Mar 3 17:03:24 2008 From: dat1965 at yahoo.com (David Thompson) Date: Mon, 3 Mar 2008 17:03:24 -0800 (PST) Subject: [sf-perl] use {strict,warnings} In-Reply-To: Message-ID: <706225.41072.qm@web55112.mail.re4.yahoo.com> --- frosty wrote: > I actually find it useful sometimes, but on average more annoying than useful. > > The useful thing is that it reminds me to be clearer in things like printing and > logging: > > use strict; > use warnings; Does this help your situation any? use warnings; no warnings qw(uninitialized); See http://perldoc.perl.org/perllexwarn.html and perldiag > my $nope = undef; > printf "You set it to '%s'\n", $nope; # warns. > printf "You set it to '%s'\n", $nope || 'UNDEF'; # better. > > But: > > my $stuff = join( "fee", "fi", "fo", $nope ); # warns, annoying (to me). > die "$nope would be nice"; # warns, annoying (to me). > > On the one hand I wish undefined values could be auto-vivified to 'UNDEF' in warn and > die, but on the other hand that's probably sqlplus poisoning my brain. > > The problem, I find, with disabling warnings is that my list of annoying warnings may > not be the same as my colleague's list. That plus you have nobody to blame but > yourself when you screw up. > > The problem with *not* doing that is there is plenty of CPAN code that spews warnings > all over your log files if you happen to have any. ____________________________________________________________________________________ Never miss a thing. Make Yahoo your home page. http://www.yahoo.com/r/hs From biztos at mac.com Mon Mar 3 19:04:05 2008 From: biztos at mac.com (frosty) Date: Mon, 03 Mar 2008 19:04:05 -0800 Subject: [sf-perl] use {strict,warnings} In-Reply-To: <706225.41072.qm@web55112.mail.re4.yahoo.com> References: <706225.41072.qm@web55112.mail.re4.yahoo.com> Message-ID: <486A3377-0118-1000-838A-5EDAE3F22E56-Webmail-10017@mac.com> Thanks, but that's exactly what I meant by my annoyances not being everyone's annoyances. I think disabling warnings is a slippery slope even in a local context. I suppose if everyone in an organization agreed that uninitialized warnings were the enemy it could make sense, but then why not take your case to the Perl community at large? Of course sometimes you really have to disable warnings of some type locally or you'll go nuts, but I try to think of that as a last resort and limit it to the smallest possible context. cheers -- frosty On Monday, March 03, 2008, at 05:05PM, "David Thompson" wrote: > >Does this help your situation any? > > use warnings; > no warnings qw(uninitialized); > >See http://perldoc.perl.org/perllexwarn.html >and perldiag > >> my $nope = undef; >> printf "You set it to '%s'\n", $nope; # warns. >> printf "You set it to '%s'\n", $nope || 'UNDEF'; # better. >> >> But: >> >> my $stuff = join( "fee", "fi", "fo", $nope ); # warns, annoying (to me). >> die "$nope would be nice"; # warns, annoying (to me). >> >> On the one hand I wish undefined values could be auto-vivified to 'UNDEF' in warn and >> die, but on the other hand that's probably sqlplus poisoning my brain. >> >> The problem, I find, with disabling warnings is that my list of annoying warnings may >> not be the same as my colleague's list. That plus you have nobody to blame but >> yourself when you screw up. >> >> The problem with *not* doing that is there is plenty of CPAN code that spews warnings >> all over your log files if you happen to have any. > > > > ____________________________________________________________________________________ >Never miss a thing. Make Yahoo your home page. >http://www.yahoo.com/r/hs > > From rdm at cfcl.com Mon Mar 3 19:26:11 2008 From: rdm at cfcl.com (Rich Morin) Date: Mon, 3 Mar 2008 19:26:11 -0800 Subject: [sf-perl] use {strict,warnings} In-Reply-To: References: <20080302232810.GA86399@fu.funkspiel.org> <07D10AFC-5221-42A8-8C79-2A3C962EEA13@mac.com> <200803030844.m238iDWP037982@kzsu.stanford.edu> Message-ID: At 03:43 -0800 3/3/08, frosty wrote: > The problem with *not* doing that is there is plenty of > CPAN code that spews warnings all over your log files if > you happen to have any. ... use this; # Look, Ma... use that; # No warnings! ... use strict; use warnings; ... -r -- http://www.cfcl.com/rdm Rich Morin http://www.cfcl.com/rdm/resume rdm at cfcl.com http://www.cfcl.com/rdm/weblog +1 650-873-7841 Technical editing and writing, programming, and web development From doom at kzsu.stanford.edu Mon Mar 3 20:04:42 2008 From: doom at kzsu.stanford.edu (Joe Brenner) Date: Mon, 03 Mar 2008 20:04:42 -0800 Subject: [sf-perl] use {strict,warnings} In-Reply-To: <486A3377-0118-1000-838A-5EDAE3F22E56-Webmail-10017@mac.com> References: <706225.41072.qm@web55112.mail.re4.yahoo.com> <486A3377-0118-1000-838A-5EDAE3F22E56-Webmail-10017@mac.com> Message-ID: <200803040404.m2444g8r055623@kzsu.stanford.edu> frosty wrote: > I think disabling warnings is a slippery slope even in a local > context. I suppose if everyone in an organization agreed that > uninitialized warnings were the enemy it could make sense, but then > why not take your case to the Perl community at large? > Of course sometimes you really have to disable warnings of some type > locally or you'll go nuts, but I try to think of that as a last resort > and limit it to the smallest possible context. I think I'm largely in agreement with you here. I do know that you can shut off a class of warnings lexically, and I hope it would be obvious that it's best to do this as minimally as possible. I think the question for me might be boiled down to this one code example. Is it better to code something like this: use warnings; use strict; my @phrases = ( 'The Rediscovery of Man', 'The Instrumentality', 'D\'Joan', ); foreach my $phrase (@phrases) { my ($alpha, $ralpha, $blvd) = split ' ', $phrase; { no warnings 'uninitialized'; print " 1: $alpha\n 2: $ralpha\n 3: $blvd\n\n"; } } Or should that last loop be handled something like this: foreach my $phrase (@phrases) { my ($alpha, $ralpha, $blvd) = (' ', ' ', ' '); ($alpha, $ralpha, $blvd) = split ' ', $phrase; $alpha ||=''; $ralpha ||=''; $blvd ||=''; print " 1: $alpha\n 2: $ralpha\n 3: $blvd\n\n"; } In this particular case it's something of a wash in terms of complexity or dangerousness, but you don't have to think as hard about the second way, so I think that one wins. I would guess that just leaving warnings on all the time wins often enough that you're better off doing it that way by default, and living with the occasional minor pain. From doom at kzsu.stanford.edu Mon Mar 3 20:13:32 2008 From: doom at kzsu.stanford.edu (Joe Brenner) Date: Mon, 03 Mar 2008 20:13:32 -0800 Subject: [sf-perl] use {strict,warnings} In-Reply-To: <200803040404.m2444g8r055623@kzsu.stanford.edu> References: <706225.41072.qm@web55112.mail.re4.yahoo.com> <486A3377-0118-1000-838A-5EDAE3F22E56-Webmail-10017@mac.com> <200803040404.m2444g8r055623@kzsu.stanford.edu> Message-ID: <200803040413.m244DW8a055734@kzsu.stanford.edu> Joe Brenner wrote: > I think the question for me might be boiled down to this one code > example. Is it better to code something like this: > > use warnings; > use strict; > > my @phrases = ( > 'The Rediscovery of Man', > 'The Instrumentality', > 'D\'Joan', > ); > > foreach my $phrase (@phrases) { > my ($alpha, $ralpha, $blvd) = split ' ', $phrase; > { > no warnings 'uninitialized'; > print " 1: $alpha\n 2: $ralpha\n 3: $blvd\n\n"; > } > } > > Or should that last loop be handled something like this: > > foreach my $phrase (@phrases) { > my ($alpha, $ralpha, $blvd) = (' ', ' ', ' '); > ($alpha, $ralpha, $blvd) = split ' ', $phrase; > $alpha ||=''; > $ralpha ||=''; > $blvd ||=''; > print " 1: $alpha\n 2: $ralpha\n 3: $blvd\n\n"; > } > > In this particular case it's something of a wash in terms of > complexity or dangerousness, but you don't have to think as > hard about the second way, so I think that one wins. > > I would guess that just leaving warnings on all the time wins > often enough that you're better off doing it that way by > default, and living with the occasional minor pain. > Sorry, that second example was supposed to be like this: foreach my $phrase (@phrases) { my ($alpha, $ralpha, $blvd) = split ' ', $phrase; $alpha ||=''; $ralpha ||=''; $blvd ||=''; print " 1: $alpha\n 2: $ralpha\n 3: $blvd\n\n"; } (I'd been experimenting with split for a minute there, making sure it behaved the way I thought it did... You can not initialize the later variables first, and expect them to stay untouched by split if there aren't enough items returned: it always defines the later items as undef.) From biztos at mac.com Tue Mar 4 09:18:31 2008 From: biztos at mac.com (Kevin Frost) Date: Tue, 4 Mar 2008 09:18:31 -0800 Subject: [sf-perl] use {strict,warnings} In-Reply-To: <200803040413.m244DW8a055734@kzsu.stanford.edu> References: <706225.41072.qm@web55112.mail.re4.yahoo.com> <486A3377-0118-1000-838A-5EDAE3F22E56-Webmail-10017@mac.com> <200803040404.m2444g8r055623@kzsu.stanford.edu> <200803040413.m244DW8a055734@kzsu.stanford.edu> Message-ID: That's a good example. I would say you can rewrite it so it throws no warnings and is still reasonably elegant, but I would use the first version (no warnings) before using the second (gratuitous ||=). The warnings are telling you that your assumption there are three parts to each phrase is dubious. That's a useful warning, though it's arguably a nit-picking sort of usefulness. You could do something like this: # pretty ugly, but it works and the print didn't change: my ( $alpha, $ralpha, $blvd ) = map { defined $_ ? $_ : '' } split( /\s+/, $phrase, 3 ), '', '', ''; print " 1: $alpha\n 2: $ralpha\n 3: $blvd\n\n"; ...or like this: my $i = 0; print join( "\n", map { $i++; "$i: $_"; } split( /\s+/, $phrase ) ), "\n\n"; ...or like this if you don't care about 4+: my $i = 0; print join( "\n", map { $i++; "$i: $_"; } split( /\s+/, $phrase, 3 ) ), "\n\n"; ...but if you don't like those approaches then I think the no-warnings bit is in exactly the right spot. cheers -- f. On Mar 3, 2008, at 8:13 PM, Joe Brenner wrote: > Joe Brenner wrote: > >> I think the question for me might be boiled down to this one code >> example. Is it better to code something like this: >> >> use warnings; >> use strict; >> >> my @phrases = ( >> 'The Rediscovery of Man', >> 'The Instrumentality', >> 'D\'Joan', >> ); >> >> foreach my $phrase (@phrases) { >> my ($alpha, $ralpha, $blvd) = split ' ', $phrase; >> { >> no warnings 'uninitialized'; >> print " 1: $alpha\n 2: $ralpha\n 3: $blvd\n\n"; >> } >> } >> >> Or should that last loop be handled something like this: >> >> foreach my $phrase (@phrases) { >> my ($alpha, $ralpha, $blvd) = (' ', ' ', ' '); >> ($alpha, $ralpha, $blvd) = split ' ', $phrase; >> $alpha ||=''; >> $ralpha ||=''; >> $blvd ||=''; >> print " 1: $alpha\n 2: $ralpha\n 3: $blvd\n\n"; >> } >> >> In this particular case it's something of a wash in terms of >> complexity or dangerousness, but you don't have to think as >> hard about the second way, so I think that one wins. >> >> I would guess that just leaving warnings on all the time wins >> often enough that you're better off doing it that way by >> default, and living with the occasional minor pain. >> > > Sorry, that second example was supposed to be like this: > > foreach my $phrase (@phrases) { > my ($alpha, $ralpha, $blvd) = split ' ', $phrase; > $alpha ||=''; > $ralpha ||=''; > $blvd ||=''; > print " 1: $alpha\n 2: $ralpha\n 3: $blvd\n\n"; > } > > > (I'd been experimenting with split for a minute there, making > sure it behaved the way I thought it did... You can not > initialize the later variables first, and expect them to stay > untouched by split if there aren't enough items returned: it > always defines the later items as undef.) > > _______________________________________________ > SanFrancisco-pm mailing list > SanFrancisco-pm at pm.org > http://mail.pm.org/mailman/listinfo/sanfrancisco-pm From biztos at mac.com Tue Mar 4 09:26:04 2008 From: biztos at mac.com (Kevin Frost) Date: Tue, 4 Mar 2008 09:26:04 -0800 Subject: [sf-perl] use {strict,warnings} In-Reply-To: References: <706225.41072.qm@web55112.mail.re4.yahoo.com> <486A3377-0118-1000-838A-5EDAE3F22E56-Webmail-10017@mac.com> <200803040404.m2444g8r055623@kzsu.stanford.edu> <200803040413.m244DW8a055734@kzsu.stanford.edu> Message-ID: <87527184-8708-486D-A336-94BD2E229ED6@mac.com> Sorry, I forgot how short the e-mail elves cut their lines. Previous code, shorter width: # You could do something like this: # pretty ugly, but it works and the print didn't change: my ( $alpha, $ralpha, $blvd ) = map { defined $_ ? $_ : '' } split( /\s+/, $phrase, 3 ), '', '', ''; print " 1: $alpha\n 2: $ralpha\n 3: $blvd\n\n"; # ...or like this: my $i = 0; print join( "\n", map { $i++; "$i: $_"; } split( /\s+/, $phrase ) ), "\n\n"; # ...or like this if you don't care about 4+: my $i = 0; print join( "\n", map { $i++; "$i: $_"; } split( /\s+/, $phrase, 3 ) ), "\n\n"; From biztos at mac.com Tue Mar 4 09:46:09 2008 From: biztos at mac.com (Kevin Frost) Date: Tue, 4 Mar 2008 09:46:09 -0800 Subject: [sf-perl] use {strict,warnings} In-Reply-To: References: <20080302232810.GA86399@fu.funkspiel.org> <07D10AFC-5221-42A8-8C79-2A3C962EEA13@mac.com> <200803030844.m238iDWP037982@kzsu.stanford.edu> Message-ID: That's a cool trick but it only works if the underlying module doesn't use warnings. --snip (Foo.pm)-- package Foo; use strict; use warnings; sub bar { my ( $class, $val ) = @_; return "you said '$val'"; } 1; --snip (Bar.pm)-- package Bar; use Foo; sub baz { my $class = shift; my $result = $class->_sloppy_operation; return Foo->bar($result); } sub _sloppy_operation { return; } 1; --snip-- Then, alas, this throws a warning: use Bar; use strict; use warnings; my $x = Bar->baz(); -- frosty On Mar 3, 2008, at 7:26 PM, Rich Morin wrote: > At 03:43 -0800 3/3/08, frosty wrote: >> The problem with *not* doing that is there is plenty of >> CPAN code that spews warnings all over your log files if >> you happen to have any. > > ... > use this; # Look, Ma... > use that; # No warnings! > ... > use strict; > use warnings; > ... > > -r > -- > http://www.cfcl.com/rdm Rich Morin > http://www.cfcl.com/rdm/resume rdm at cfcl.com > http://www.cfcl.com/rdm/weblog +1 650-873-7841 From doom at kzsu.stanford.edu Tue Mar 4 16:05:20 2008 From: doom at kzsu.stanford.edu (Joe Brenner) Date: Tue, 04 Mar 2008 16:05:20 -0800 Subject: [sf-perl] use {strict,warnings} In-Reply-To: References: <706225.41072.qm@web55112.mail.re4.yahoo.com> <486A3377-0118-1000-838A-5EDAE3F22E56-Webmail-10017@mac.com> <200803040404.m2444g8r055623@kzsu.stanford.edu> <200803040413.m244DW8a055734@kzsu.stanford.edu> Message-ID: <200803050005.m2505KNN071981@kzsu.stanford.edu> Kevin Frost wrote: > That's a good example. I would say you can rewrite it so it throws no > warnings and is still reasonably elegant, but I would use the first > version (no warnings) before using the second (gratuitous ||=). > > The warnings are telling you that your assumption there are three > parts to each phrase is dubious. That's a useful warning, though it's > arguably a nit-picking sort of usefulness. > > You could do something like this: > > # pretty ugly, but it works and the print didn't change: > my ( $alpha, $ralpha, $blvd ) = > map { defined $_ ? $_ : '' } split( /\s+/, $phrase, 3 ), '', > '', ''; > print " 1: $alpha\n 2: $ralpha\n 3: $blvd\n\n"; > > ...or like this: > > my $i = 0; > print join( "\n", map { $i++; "$i: $_"; } split( /\s+/, > $phrase ) ), "\n\n"; > > ...or like this if you don't care about 4+: > > my $i = 0; > print join( "\n", map { $i++; "$i: $_"; } split( /\s+/, $phrase, > 3 ) ), > "\n\n"; > > ...but if you don't like those approaches then I think the no-warnings > bit is in exactly the right spot. It isn't so much that I don't like them, it's that working out something like one of those solutions would've taken me a few minutes, and worse, it probably would take someone reading the code a few minutes to understand. (I did have the thought if I was splitting to an array, with an indefinite number of items, it would be time to use map.) Like I was saying before: > >> In this particular case it's something of a wash in terms of > >> complexity or dangerousness, but you don't have to think as > >> hard about the second way [leaving warnings on and > >> manually applying a default], so I think that one wins. Conserving mental effort is the goal, not reducing the number of lines of code. From biztos at mac.com Tue Mar 4 16:25:16 2008 From: biztos at mac.com (frosty) Date: Tue, 04 Mar 2008 16:25:16 -0800 Subject: [sf-perl] use {strict,warnings} In-Reply-To: <200803050005.m2505KNN071981@kzsu.stanford.edu> References: <706225.41072.qm@web55112.mail.re4.yahoo.com> <486A3377-0118-1000-838A-5EDAE3F22E56-Webmail-10017@mac.com> <200803040404.m2444g8r055623@kzsu.stanford.edu> <200803040413.m244DW8a055734@kzsu.stanford.edu> <200803050005.m2505KNN071981@kzsu.stanford.edu> Message-ID: > Conserving mental effort is the goal, not reducing the number > of lines of code. Well put. That's a nice thing to keep in mind when trying to measure "code kwalitee" even though it's very hand-wavy. -- f. From nheller at silcon.com Wed Mar 5 15:46:51 2008 From: nheller at silcon.com (nheller at silcon.com) Date: Wed, 5 Mar 2008 15:46:51 -0800 (PST) Subject: [sf-perl] Can't figure this one out Message-ID: <1602.66.93.171.131.1204760811.squirrel@webmail.silcon.com> Here's an error that I can't figure out for the life of me. The code is short; I can't figure out why the compiler thinks $action (on the marked line) is a bare word. The actual error message follows the source code. I would really appreciate any help. { my ($q, $ins, $action, %p, $p); $q = new CGI; $action = $q->param('action'); $action = 'start' unless $action; if ($action =~ /start/i) { <-------- line 511, the offender &MainPage($q, \%p); } elsif ($action =~ /new/i || $action =~ /del/i || $action =~ /edt/i || $action =~ /save/i ) { [imiuser at adopt nheller]$ perl -c ad_cases.cgi Bareword "action" not allowed while "strict subs" in use at ad_cases.cgi line 511. ad_cases.cgi had compilation errors. [imiuser at adopt nheller]$ vi ad_cases.cgi [imiuser at adopt nheller]$ From andy at petdance.com Wed Mar 5 15:49:46 2008 From: andy at petdance.com (Andy Lester) Date: Wed, 5 Mar 2008 17:49:46 -0600 Subject: [sf-perl] Can't figure this one out In-Reply-To: <1602.66.93.171.131.1204760811.squirrel@webmail.silcon.com> References: <1602.66.93.171.131.1204760811.squirrel@webmail.silcon.com> Message-ID: <052BC823-ACA7-47B4-A7DD-DB4AA974F521@petdance.com> On Mar 5, 2008, at 5:46 PM, nheller at silcon.com wrote: > if ($action =~ /start/i) { <-------- line 511, the offender > &MainPage($q, \%p); > } > elsif ($action =~ /new/i || > $action =~ /del/i || > $action =~ /edt/i || > $action =~ /save/i ) > { > > > > [imiuser at adopt nheller]$ perl -c ad_cases.cgi > Bareword "action" not allowed while "strict subs" in use at > ad_cases.cgi > line 511. > ad_cases.cgi had compilation errors. The "at line 511" really means "the statement that starts on line 511" but it looks like you have a cascading if/else chain, and so the ENTIRE CHAIN is "at line 511". Break up the else/ifs and you'll get a better pointer to the offending line. xoxo, Andy -- Andy Lester => andy at petdance.com => www.petdance.com => AIM:petdance From sergey.fetisov at ask.com Wed Mar 5 16:32:46 2008 From: sergey.fetisov at ask.com (Sergey Fetisov) Date: Wed, 5 Mar 2008 16:32:46 -0800 Subject: [sf-perl] Can't figure this one out In-Reply-To: <052BC823-ACA7-47B4-A7DD-DB4AA974F521@petdance.com> References: <1602.66.93.171.131.1204760811.squirrel@webmail.silcon.com> <052BC823-ACA7-47B4-A7DD-DB4AA974F521@petdance.com> Message-ID: <09AD1BE32C2FCF47A8049BDA1D0449ED0242CF8F@Site1Mail04.jeeves.ask.info> On Mar 5, 2008, at 5:46 PM, nheller at silcon.com wrote: >> if ($action =~ /start/i) { <-------- line 511, the offender >> &MainPage($q, \%p); >> } >> elsif ($action =~ /new/i || >> $action =~ /del/i || >> $action =~ /edt/i || >> $action =~ /save/i ) >> { >> >> >> >> [imiuser at adopt nheller]$ perl -c ad_cases.cgi Bareword "action" not >> allowed while "strict subs" in use at ad_cases.cgi line 511. >> ad_cases.cgi had compilation errors. >The "at line 511" really means "the statement that starts on line 511" >but it looks like you have a cascading if/else chain, and so the ENTIRE CHAIN is "at line 511". >Break up the else/ifs and you'll get a better pointer to the offending line. >xoxo, >Andy ------------------------------------------------------------------------ ------------ Yep, seems like a some line inside of the if/else statement caused the error By the way if ($action =~ /start/i) { &MainPage($q, \%p); } elsif ($action =~ /new|del|edt|save/i ) { { seems better to me Sergey From doom at kzsu.stanford.edu Wed Mar 5 17:23:19 2008 From: doom at kzsu.stanford.edu (Joe Brenner) Date: Wed, 05 Mar 2008 17:23:19 -0800 Subject: [sf-perl] Can't figure this one out In-Reply-To: <1602.66.93.171.131.1204760811.squirrel@webmail.silcon.com> References: <1602.66.93.171.131.1204760811.squirrel@webmail.silcon.com> Message-ID: <200803060123.m261NJFt094694@kzsu.stanford.edu> nheller at silcon.com wrote: > Here's an error that I can't figure out for the life of me. > The code is short; I can't figure out why the compiler thinks $action (on > the marked line) is a bare word. > > The actual error message follows the source code. > I would really appreciate any help. > > { > my ($q, $ins, $action, %p, $p); > > $q = new CGI; > $action = $q->param('action'); > $action = 'start' unless $action; > > if ($action =~ /start/i) { <-------- line 511, the offender > &MainPage($q, \%p); > } > elsif ($action =~ /new/i || > $action =~ /del/i || > $action =~ /edt/i || > $action =~ /save/i ) > { My experience has been that with compound booleans like this, you're better off using more parens than you think you need: elsif ( ($action =~ /new/i) || ($action =~ /del/i) || ($action =~ /edt/i) || ($action =~ /save/i) ) From doom at kzsu.stanford.edu Wed Mar 5 17:26:16 2008 From: doom at kzsu.stanford.edu (Joe Brenner) Date: Wed, 05 Mar 2008 17:26:16 -0800 Subject: [sf-perl] Can't figure this one out In-Reply-To: <09AD1BE32C2FCF47A8049BDA1D0449ED0242CF8F@Site1Mail04.jeeves.ask.info> References: <1602.66.93.171.131.1204760811.squirrel@webmail.silcon.com> <052BC823-ACA7-47B4-A7DD-DB4AA974F521@petdance.com> <09AD1BE32C2FCF47A8049BDA1D0449ED0242CF8F@Site1Mail04.jeeves.ask.info> Message-ID: <200803060126.m261QGCR094802@kzsu.stanford.edu> Sergey Fetisov wrote: > nheller at silcon.com wrote: > > >> if ($action =~ /start/i) { <-------- line 511, the offender > >> &MainPage($q, \%p); > >> } > >> elsif ($action =~ /new/i || > >> $action =~ /del/i || > >> $action =~ /edt/i || > >> $action =~ /save/i ) > >> { > >> > >> [imiuser at adopt nheller]$ perl -c ad_cases.cgi Bareword "action" not > >> allowed while "strict subs" in use at ad_cases.cgi line 511. > >> ad_cases.cgi had compilation errors. > >The "at line 511" really means "the statement that starts on line 511" > > >but it looks like you have a cascading if/else chain, and so the ENTIRE > CHAIN is "at line 511". > > >Break up the else/ifs and you'll get a better pointer to the offending > line. > ------------ > > Yep, seems like a some line inside of the if/else statement caused the > error > > By the way > > if ($action =~ /start/i) { > &MainPage($q, \%p); > } elsif ($action =~ /new|del|edt|save/i ) { > > { > > seems better to me It's more compact, but I bet it runs slower. This might even be a case where performance matters (i.e. if the cgi script sees a lot of traffic). From andy at petdance.com Wed Mar 5 17:30:21 2008 From: andy at petdance.com (Andy Lester) Date: Wed, 5 Mar 2008 19:30:21 -0600 Subject: [sf-perl] Can't figure this one out In-Reply-To: <200803060126.m261QGCR094802@kzsu.stanford.edu> References: <1602.66.93.171.131.1204760811.squirrel@webmail.silcon.com> <052BC823-ACA7-47B4-A7DD-DB4AA974F521@petdance.com> <09AD1BE32C2FCF47A8049BDA1D0449ED0242CF8F@Site1Mail04.jeeves.ask.info> <200803060126.m261QGCR094802@kzsu.stanford.edu> Message-ID: <1B199114-EC6C-462C-91E3-5845CDDAB253@petdance.com> On Mar 5, 2008, at 7:26 PM, Joe Brenner wrote: > It's more compact, but I bet it runs slower. This might even be a > case where performance matters (i.e. if the cgi script sees a lot of > traffic). No CGI script is going to be bottlenecked by a regex deciding an action to take, regardless of how much traffic it gets. xoa -- Andy Lester => andy at petdance.com => www.petdance.com => AIM:petdance From extasia at extasia.org Wed Mar 5 17:33:41 2008 From: extasia at extasia.org (David Alban) Date: Wed, 5 Mar 2008 17:33:41 -0800 Subject: [sf-perl] Can't figure this one out In-Reply-To: <200803060126.m261QGCR094802@kzsu.stanford.edu> References: <1602.66.93.171.131.1204760811.squirrel@webmail.silcon.com> <052BC823-ACA7-47B4-A7DD-DB4AA974F521@petdance.com> <09AD1BE32C2FCF47A8049BDA1D0449ED0242CF8F@Site1Mail04.jeeves.ask.info> <200803060126.m261QGCR094802@kzsu.stanford.edu> Message-ID: <4c714a9c0803051733g55c55f26q3ff66af2344ef787@mail.gmail.com> with respect to: /start/i consider beginning of string and end of string anchors unless you want also to match: restart starts started if it weren't for the /i modifier, i'd say just use 'eq'. actually--you could do: lc $action eq 'start' > > if ($action =~ /start/i) { > > &MainPage($q, \%p); -- Live in a world of your own, but always welcome visitors. From sphink at gmail.com Wed Mar 5 17:33:47 2008 From: sphink at gmail.com (Steve Fink) Date: Wed, 5 Mar 2008 17:33:47 -0800 Subject: [sf-perl] Can't figure this one out In-Reply-To: <200803060126.m261QGCR094802@kzsu.stanford.edu> References: <1602.66.93.171.131.1204760811.squirrel@webmail.silcon.com> <052BC823-ACA7-47B4-A7DD-DB4AA974F521@petdance.com> <09AD1BE32C2FCF47A8049BDA1D0449ED0242CF8F@Site1Mail04.jeeves.ask.info> <200803060126.m261QGCR094802@kzsu.stanford.edu> Message-ID: <7d7f2e8c0803051733s141f0f6k6ef0f90ffa3d100b@mail.gmail.com> > > By the way > > > > if ($action =~ /start/i) { > > &MainPage($q, \%p); > > } elsif ($action =~ /new|del|edt|save/i ) { > > > > { > > > > seems better to me > > It's more compact, but I bet it runs slower. This might even be a > case where performance matters (i.e. if the cgi script sees a lot of > traffic). I'll take that bet. I bet the all-regex version is faster. Especially on newer versions of Perl that have the trie optimization, but even without that I'd guess that it's faster. If I weren't so damn lazy, I'd write a benchmark to test it. But I can't be bothered, because there's no way that the performance of that line of code is going to be significant compared to the processing and page generation. (And if this is a CGI and not mod_perl, the startup time is going to be orders of magnitude more than all that anyway.) From doom at kzsu.stanford.edu Wed Mar 5 17:51:56 2008 From: doom at kzsu.stanford.edu (Joe Brenner) Date: Wed, 05 Mar 2008 17:51:56 -0800 Subject: [sf-perl] Can't figure this one out In-Reply-To: <7d7f2e8c0803051733s141f0f6k6ef0f90ffa3d100b@mail.gmail.com> References: <1602.66.93.171.131.1204760811.squirrel@webmail.silcon.com> <052BC823-ACA7-47B4-A7DD-DB4AA974F521@petdance.com> <09AD1BE32C2FCF47A8049BDA1D0449ED0242CF8F@Site1Mail04.jeeves.ask.info> <200803060126.m261QGCR094802@kzsu.stanford.edu> <7d7f2e8c0803051733s141f0f6k6ef0f90ffa3d100b@mail.gmail.com> Message-ID: <200803060152.m261puJE095277@kzsu.stanford.edu> Steve Fink wrote: > > > By the way > > > > > > if ($action =~ /start/i) { > > > &MainPage($q, \%p); > > > } elsif ($action =~ /new|del|edt|save/i ) { > > > > > > { > > > > > > seems better to me > > > > It's more compact, but I bet it runs slower. This might even be a > > case where performance matters (i.e. if the cgi script sees a lot of > > traffic). > > I'll take that bet. I bet the all-regex version is faster. Especially > on newer versions of Perl that have the trie optimization, but even > without that I'd guess that it's faster. And you may already be a winner. I did a quickie benchmark and it looks like the regexp alternation version is around 17% faster even in the "worst" cases (running on perl v5.8.7). I've seen some regexps with heavy reliance on alternation that ran pretty slow, but this isn't one of them (and that was a while back in any case). Also, you (and Andy Lester) are probably right about it being a silly thing to worry about -- this session on premature optimization is now over. Code and results follow: my $count = 10000000; my $result = timethese($count, { 'logical_ors - start' => 'chooser_mark_1( "start" )', 'regexp_alternation - start' => 'chooser_mark_2( "start" )', }); $result = timethese($count, { 'logical_ors - edt' => 'chooser_mark_1( "edt" )', 'regexp_alternation - edt' => 'chooser_mark_2( "edt" )', }); $result = timethese($count, { 'logical_ors - save' => 'chooser_mark_1( "save" )', 'regexp_alternation - save' => 'chooser_mark_2( "save" )', }); sub chooser_mark_1 { my $action = shift; my $branch; if ($action =~ /start/i) { $branch = 1; } elsif ($action =~ /new/i || $action =~ /del/i || $action =~ /edt/i || $action =~ /save/i ) { $branch = 2; } return $branch; } sub chooser_mark_2 { my $action = shift; my $branch; if ($action =~ /start/i) { $branch = 1; } elsif ($action =~ /new|del|edt|save/i ) { $branch = 2; } return $branch; } Results: Benchmark: timing 10000000 iterations of logical_ors - start, regexp_alternation - start... logical_ors - start: 18 wallclock secs (16.96 usr + 0.33 sys = 17.29 CPU) @ 578369.00/s (n=10000000) regexp_alternation - start: 18 wallclock secs (16.83 usr + 0.33 sys = 17.16 CPU) @ 582750.58/s (n=10000000) Benchmark: timing 10000000 iterations of logical_ors - edt, regexp_alternation - edt... logical_ors - edt: 22 wallclock secs (21.67 usr + 0.42 sys = 22.09 CPU) @ 452693.53/s (n=10000000) regexp_alternation - edt: 17 wallclock secs (18.15 usr + 0.37 sys = 18.52 CPU) @ 539956.80/s (n=10000000) Benchmark: timing 10000000 iterations of logical_ors - save, regexp_alternation - save... logical_ors - save: 23 wallclock secs (23.53 usr + 0.48 sys = 24.01 CPU) @ 416493.13/s (n=10000000) regexp_alternation - save: 19 wallclock secs (18.46 usr + 0.36 sys = 18.82 CPU) @ 531349.63/s (n=10000000) > _______________________________________________ > SanFrancisco-pm mailing list > SanFrancisco-pm at pm.org > http://mail.pm.org/mailman/listinfo/sanfrancisco-pm From nheller at silcon.com Wed Mar 5 19:12:15 2008 From: nheller at silcon.com (Neil Heller) Date: Wed, 5 Mar 2008 19:12:15 -0800 Subject: [sf-perl] Can't figure this one out In-Reply-To: <052BC823-ACA7-47B4-A7DD-DB4AA974F521@petdance.com> References: <1602.66.93.171.131.1204760811.squirrel@webmail.silcon.com> <052BC823-ACA7-47B4-A7DD-DB4AA974F521@petdance.com> Message-ID: <000001c87f37$e15a4ee0$a40eeca0$@com> The "at line 511" really means "the statement that starts on line 511" but it looks like you have a cascading if/else chain, and so the ENTIRE CHAIN is "at line 511". Break up the else/ifs and you'll get a better pointer to the offending line. Thud (sound of the heal of my hand hitting my forehead). Thanks a lot. I even think I know which one is the offender: the one I wrote. Neil Heller From doom at kzsu.stanford.edu Wed Mar 5 19:51:46 2008 From: doom at kzsu.stanford.edu (Joe Brenner) Date: Wed, 05 Mar 2008 19:51:46 -0800 Subject: [sf-perl] Can't figure this one out In-Reply-To: <200803060152.m261puJE095277@kzsu.stanford.edu> References: <1602.66.93.171.131.1204760811.squirrel@webmail.silcon.com> <052BC823-ACA7-47B4-A7DD-DB4AA974F521@petdance.com> <09AD1BE32C2FCF47A8049BDA1D0449ED0242CF8F@Site1Mail04.jeeves.ask.info> <200803060126.m261QGCR094802@kzsu.stanford.edu> <7d7f2e8c0803051733s141f0f6k6ef0f90ffa3d100b@mail.gmail.com> <200803060152.m261puJE095277@kzsu.stanford.edu> Message-ID: <200803060351.m263pkug096743@kzsu.stanford.edu> Joe Brenner wrote: > Steve Fink wrote: > > > > By the way > > > > > > > > if ($action =~ /start/i) { > > > > &MainPage($q, \%p); > > > > } elsif ($action =~ /new|del|edt|save/i ) { > > > > > > > > { > > > > > > > > seems better to me > > > > > > It's more compact, but I bet it runs slower. This might even be a > > > case where performance matters (i.e. if the cgi script sees a lot of > > > traffic). > > > > I'll take that bet. I bet the all-regex version is faster. Especially > > on newer versions of Perl that have the trie optimization, but even > > without that I'd guess that it's faster. > > And you may already be a winner. > > I did a quickie benchmark and it looks like the regexp alternation > version is around 17% faster even in the "worst" cases (running on > perl v5.8.7). I've seen some regexps with heavy reliance on alternation > that ran pretty slow, but this isn't one of them (and that was > a while back in any case). Funny thing though... just for the hell of it I ran the same code under perl 5.10 (really, 5.9.5), and the results came out the other way, with the alternation regexp being a bit slower (~25%) than the stack of boolean ors. Weird. No, I take it back, it's not that weird: the Debian/Ubuntu version of 5.8.7 was built very differently from my 5.9.5 build: perl 5.8.7: Compile-time options: MULTIPLICITY USE_ITHREADS USE_64_BIT_INT USE_64_BIT_ALL USE_LARGE_FILES PERL_IMPLICIT_CONTEXT perl 5.9.5: Compile-time options: PERL_DONT_CREATE_GVSV PERL_MALLOC_WRAP USE_64_BIT_ALL USE_64_BIT_INT USE_LARGE_FILES USE_PERLIO From biztos at mac.com Wed Mar 5 21:58:30 2008 From: biztos at mac.com (Kevin Frost) Date: Wed, 5 Mar 2008 21:58:30 -0800 Subject: [sf-perl] Can't figure this one out In-Reply-To: <200803060351.m263pkug096743@kzsu.stanford.edu> References: <1602.66.93.171.131.1204760811.squirrel@webmail.silcon.com> <052BC823-ACA7-47B4-A7DD-DB4AA974F521@petdance.com> <09AD1BE32C2FCF47A8049BDA1D0449ED0242CF8F@Site1Mail04.jeeves.ask.info> <200803060126.m261QGCR094802@kzsu.stanford.edu> <7d7f2e8c0803051733s141f0f6k6ef0f90ffa3d100b@mail.gmail.com> <200803060152.m261puJE095277@kzsu.stanford.edu> <200803060351.m263pkug096743@kzsu.stanford.edu> Message-ID: <1F9AF634-A001-4B5E-BA9E-E63BBA816F59@mac.com> There is also a Switch module if you miss your case/esac. Haven't used it in years and never benchmarked it, and now I would rather lean towards a dispatch model, but IIRC it did its job well. -- frosty (via iPhone) On Mar 5, 2008, at 7:51 PM, Joe Brenner wrote: > > Joe Brenner wrote: >> Steve Fink wrote: >>>>> By the way >>>>> >>>>> if ($action =~ /start/i) { >>>>> &MainPage($q, \%p); >>>>> } elsif ($action =~ /new|del|edt|save/i ) { >>>>> >>>>> { >>>>> >>>>> seems better to me >>>> >>>> It's more compact, but I bet it runs slower. This might even be a >>>> case where performance matters (i.e. if the cgi script sees a lot >>>> of >>>> traffic). >>> >>> I'll take that bet. I bet the all-regex version is faster. >>> Especially >>> on newer versions of Perl that have the trie optimization, but even >>> without that I'd guess that it's faster. >> >> And you may already be a winner. >> >> I did a quickie benchmark and it looks like the regexp alternation >> version is around 17% faster even in the "worst" cases (running on >> perl v5.8.7). I've seen some regexps with heavy reliance on >> alternation >> that ran pretty slow, but this isn't one of them (and that was >> a while back in any case). > > Funny thing though... just for the hell of it I ran the same code > under > perl 5.10 (really, 5.9.5), and the results came out the other way, > with > the alternation regexp being a bit slower (~25%) than the stack of > boolean ors. Weird. > > No, I take it back, it's not that weird: the Debian/Ubuntu version of > 5.8.7 was built very differently from my 5.9.5 build: > > perl 5.8.7: > Compile-time options: MULTIPLICITY USE_ITHREADS USE_64_BIT_INT > USE_64_BIT_ALL USE_LARGE_FILES > PERL_IMPLICIT_CONTEXT > > perl 5.9.5: > Compile-time options: PERL_DONT_CREATE_GVSV PERL_MALLOC_WRAP > USE_64_BIT_ALL USE_64_BIT_INT USE_LARGE_FILES > USE_PERLIO > > _______________________________________________ > SanFrancisco-pm mailing list > SanFrancisco-pm at pm.org > http://mail.pm.org/mailman/listinfo/sanfrancisco-pm From andy at petdance.com Wed Mar 5 22:03:21 2008 From: andy at petdance.com (Andy Lester) Date: Thu, 6 Mar 2008 00:03:21 -0600 Subject: [sf-perl] Can't figure this one out In-Reply-To: <1F9AF634-A001-4B5E-BA9E-E63BBA816F59@mac.com> References: <1602.66.93.171.131.1204760811.squirrel@webmail.silcon.com> <052BC823-ACA7-47B4-A7DD-DB4AA974F521@petdance.com> <09AD1BE32C2FCF47A8049BDA1D0449ED0242CF8F@Site1Mail04.jeeves.ask.info> <200803060126.m261QGCR094802@kzsu.stanford.edu> <7d7f2e8c0803051733s141f0f6k6ef0f90ffa3d100b@mail.gmail.com> <200803060152.m261puJE095277@kzsu.stanford.edu> <200803060351.m263pkug096743@kzsu.stanford.edu> <1F9AF634-A001-4B5E-BA9E-E63BBA816F59@mac.com> Message-ID: <4A0F0920-A72D-4D48-A892-63BDE41DA43C@petdance.com> On Mar 5, 2008, at 11:58 PM, Kevin Frost wrote: > There is also a Switch module if you miss your case/esac. And Perl 5.10 gives us given/when. xoa -- Andy Lester => andy at petdance.com => www.petdance.com => AIM:petdance From nheller at silcon.com Sat Mar 8 10:19:29 2008 From: nheller at silcon.com (Neil Heller) Date: Sat, 8 Mar 2008 10:19:29 -0800 Subject: [sf-perl] Debugging a CGI script - how Message-ID: <000001c88148$f32cff60$d986fe20$@com> I've been modifying a CGI script and have run into a problem that bring to mind a larger question. My script uses data from a relational database to pull information about external files. The script then displays information from the relational database and the contents of the external file. The script then continues on the next iteration - each iteration equals one entry in the relational database. If there are 3 or fewer entries in the relational database, the script works well. At the fourth entry in the relational database, Apache throws an error and the user (me at this point) receives only a generic-type error. Does anybody have any ideas about how to best go about finding the error? Neil Heller From david at fetter.org Sat Mar 8 11:17:33 2008 From: david at fetter.org (David Fetter) Date: Sat, 8 Mar 2008 11:17:33 -0800 Subject: [sf-perl] Getting Help (was Re: Debugging a CGI script - how) In-Reply-To: <000001c88148$f32cff60$d986fe20$@com> References: <000001c88148$f32cff60$d986fe20$@com> Message-ID: <20080308191733.GG23803@fetter.org> On Sat, Mar 08, 2008 at 10:19:29AM -0800, Neil Heller wrote: > I've been modifying a CGI script and have run into a problem that > bring to mind a larger question. > > My script uses data from a relational database to pull information > about external files. The script then displays information from the > relational database and the contents of the external file. The > script then continues on the next iteration - each iteration equals > one entry in the relational database. > > If there are 3 or fewer entries in the relational database, the > script works well. At the fourth entry in the relational database, > Apache throws an error and the user (me at this point) receives only > a generic-type error. > > Does anybody have any ideas about how to best go about finding the > error? Does anybody have a reference on how to write a good bug report/shout out for help? I've seen Eric Raymond's smarmy and condescending "How to Ask Smart Questions," but it misses important points, and even if it didn't, a person reading it is unlikely to get further than the first couple of paragraphs unless that person is a core-deep masochist. Anybody? Cheers, David. -- David Fetter http://fetter.org/ Phone: +1 415 235 3778 AIM: dfetter666 Yahoo!: dfetter Skype: davidfetter XMPP: david.fetter at gmail.com Remember to vote! Consider donating to Postgres: http://www.postgresql.org/about/donate From doom at kzsu.stanford.edu Sat Mar 8 12:32:02 2008 From: doom at kzsu.stanford.edu (Joe Brenner) Date: Sat, 08 Mar 2008 12:32:02 -0800 Subject: [sf-perl] Debugging a CGI script - how In-Reply-To: <000001c88148$f32cff60$d986fe20$@com> References: <000001c88148$f32cff60$d986fe20$@com> Message-ID: <200803082032.m28KW2Iu048334@kzsu.stanford.edu> Neil Heller wrote: > I've been modifying a CGI script and have run into a problem that bring to > mind a larger question. > > My script uses data from a relational database to pull information about > external files. The script then displays information from the relational > database and the contents of the external file. The script then continues > on the next iteration - each iteration equals one entry in the relational > database. > > If there are 3 or fewer entries in the relational database, the script works > well. At the fourth entry in the relational database, Apache throws an > error and the user (me at this point) receives only a generic-type error. > > Does anybody have any ideas about how to best go about finding the error? Have you checked the apache error log? Where are you seeing this "generic error message"? Note that if you toss in statements like: print STDERR "The value is: $value at " . __LINE__ . "\n"; That output should show up in the apache error log. At a guess, you should look at the data involved more closely: I would guess there's something in your fourth record that's messing you up, and you need to be more careful with quoting or using bind parameter ("?" placeholders) or something like that. Try some runs with different data, organized in different ways. I also might suggest that at some point you shoule spend some time to learn how to use the perl debugger, but that admittedly can be a bit of a pain in a web context. You might try to cut down your code the smallest example that reproduces the problem, then you could post the code here, and we'll look it over. From jared at wordzoo.com Sat Mar 8 12:37:10 2008 From: jared at wordzoo.com (Jared Rhine) Date: Sat, 8 Mar 2008 12:37:10 -0800 Subject: [sf-perl] Getting Help (was Re: Debugging a CGI script - how) In-Reply-To: <20080308191733.GG23803@fetter.org> References: <000001c88148$f32cff60$d986fe20$@com> <20080308191733.GG23803@fetter.org> Message-ID: > Does anybody have a reference on how to write a good bug report/shout > out for help? I've no bug-reporting guides that aren't application-specific. It seems that the crankiness experienced on this list and others boils down to these two rules: 1. Cut-and-paste the actual error message, not your summary of the error message 2. Include actual code Time and time again, inquires which include at least one of these pieces of information get an answer. Inquiries which skip both are barely worth responding to, except to repeat the above two rules. For Perl-list questions, Raymond's document should be shortened dramatically by basing around these two. (He was trying to construct a general method of question-asking, which is inherently harder than any procedure for a specific context, like an app or Perl coding.) ("generic-type error" is the funniest problem report I've seen in a while, FWIW. Probably what's going on here is the original poster is seeing a 500 error in Apache, which is indeed a generic-type error with no script-relevant info. They haven't learned yet to look in the error logs.) For what it's worth, I can see how beginners are so unstructured in their thinking as to attribute a sort of magical ability to more experienced people, to the point where their mental model is that senior developers know what the problem is from just a hand-wavey description of the problem. It's half that people don't know how to Ask Good Questions, but also that they don't understand the process experienced people use to solve problems. They can't distinguish between problems which have one or two possible answers and problems which have 1000 possible answers. When I train junior staff, it's amazing how the most effective lesson I can teach is generally "read the actual error message". "No, read it". "Repeat each word to me". "It's telling you the exact problem". "Rephrase the error message to me". Of course, experienced people know error messages often lie or are useless, but errors received by junior staff usually aren't obscure but very plain. -- Jared From doom at kzsu.stanford.edu Sat Mar 8 12:38:04 2008 From: doom at kzsu.stanford.edu (Joe Brenner) Date: Sat, 08 Mar 2008 12:38:04 -0800 Subject: [sf-perl] Getting Help (was Re: Debugging a CGI script - how) In-Reply-To: <20080308191733.GG23803@fetter.org> References: <000001c88148$f32cff60$d986fe20$@com> <20080308191733.GG23803@fetter.org> Message-ID: <200803082038.m28Kc44f048436@kzsu.stanford.edu> David Fetter wrote: > Neil Heller wrote: > > I've been modifying a CGI script and have run into a problem that > > bring to mind a larger question. > > > > My script uses data from a relational database to pull information > > about external files. The script then displays information from the > > relational database and the contents of the external file. The > > script then continues on the next iteration - each iteration equals > > one entry in the relational database. > > > > If there are 3 or fewer entries in the relational database, the > > script works well. At the fourth entry in the relational database, > > Apache throws an error and the user (me at this point) receives only > > a generic-type error. > > > > Does anybody have any ideas about how to best go about finding the > > error? > > Does anybody have a reference on how to write a good bug report/shout > out for help? I know the problem you're talking about, but Neil's question doesn't seem *all* that bad to me. It's a pretty generic question about how to debug weird problems in web/db programming... > I've seen Eric Raymond's smarmy and condescending "How to Ask Smart > Questions," but it misses important points, and even if it didn't, a > person reading it is unlikely to get further than the first couple of > paragraphs unless that person is a core-deep masochist. At the very least, it's certainly too verbose. (And as I remember it, Rick Moen has essentially disowned it at this point.) > Anybody? Some projects write their own. There are a few pages on the subject written for the emacs documentation: http://www.gnu.org/software/emacs/manual/html_node/emacs/Bugs.html From doom at kzsu.stanford.edu Sat Mar 8 12:43:11 2008 From: doom at kzsu.stanford.edu (Joe Brenner) Date: Sat, 08 Mar 2008 12:43:11 -0800 Subject: [sf-perl] Getting Help (was Re: Debugging a CGI script - how) In-Reply-To: <200803082038.m28Kc44f048436@kzsu.stanford.edu> References: <000001c88148$f32cff60$d986fe20$@com> <20080308191733.GG23803@fetter.org> <200803082038.m28Kc44f048436@kzsu.stanford.edu> Message-ID: <200803082043.m28KhBxY048532@kzsu.stanford.edu> Joe Brenner wrote: > Some projects write their own. There are a few pages on the subject > written for the emacs documentation: > > http://www.gnu.org/software/emacs/manual/html_node/emacs/Bugs.html Ah, of course. There's Mark Jason Dominus on the subject: http://perl.plover.com/Questions.html From biztos at mac.com Sat Mar 8 12:54:11 2008 From: biztos at mac.com (Kevin Frost) Date: Sat, 8 Mar 2008 12:54:11 -0800 Subject: [sf-perl] Debugging a CGI script - how In-Reply-To: <200803082032.m28KW2Iu048334@kzsu.stanford.edu> References: <000001c88148$f32cff60$d986fe20$@com> <200803082032.m28KW2Iu048334@kzsu.stanford.edu> Message-ID: <40389DDC-69A7-4F27-9116-7B74E23A690D@mac.com> I would also add that if you're doing fetchrow_arrayref or similar you might want to temporarily switch to _hashref and use the Dumper: use Data::Dumper qw(Dumper); # ...set up db connection and query, etc. my $rownum = 0; while (my $row = $sth->fetchrow_hashref) { # 4th on is tricky... $rownum ++; printf STDERR "ROW %d: %s\n", $rownum, Dumper($row); } ...or words to that effect. -- f. On Mar 8, 2008, at 12:32 PM, Joe Brenner wrote: > > print STDERR "The value is: $value at " . __LINE__ . "\n"; From doom at kzsu.stanford.edu Sat Mar 8 13:19:38 2008 From: doom at kzsu.stanford.edu (Joe Brenner) Date: Sat, 08 Mar 2008 13:19:38 -0800 Subject: [sf-perl] Debugging a CGI script - how In-Reply-To: <40389DDC-69A7-4F27-9116-7B74E23A690D@mac.com> References: <000001c88148$f32cff60$d986fe20$@com> <200803082032.m28KW2Iu048334@kzsu.stanford.edu> <40389DDC-69A7-4F27-9116-7B74E23A690D@mac.com> Message-ID: <200803082119.m28LJcnW049109@kzsu.stanford.edu> Kevin Frost wrote: > Joe Brenner wrote: > > print STDERR "The value is: $value at " . __LINE__ . "\n"; > I would also add that if you're doing fetchrow_arrayref or similar you > might want to temporarily switch to _hashref and use the Dumper: > > use Data::Dumper qw(Dumper); > > # ...set up db connection and query, etc. > > > my $rownum = 0; > while (my $row = $sth->fetchrow_hashref) { > # 4th on is tricky... > $rownum ++; > printf STDERR "ROW %d: %s\n", $rownum, Dumper($row); > > } > > ...or words to that effect. Sure, sounds good. I just thought I'd make the point that there isn't any particularly need to avoid using fetchrow_hashref. As I remember it, the performance penalty on doing that was fixed a while back. From garth.webb at gmail.com Sat Mar 8 13:21:34 2008 From: garth.webb at gmail.com (Garth Webb) Date: Sat, 8 Mar 2008 13:21:34 -0800 Subject: [sf-perl] Debugging a CGI script - how In-Reply-To: <200803082032.m28KW2Iu048334@kzsu.stanford.edu> References: <000001c88148$f32cff60$d986fe20$@com> <200803082032.m28KW2Iu048334@kzsu.stanford.edu> Message-ID: On Sat, Mar 8, 2008 at 12:32 PM, Joe Brenner wrote: > > Neil Heller wrote: > > > I've been modifying a CGI script and have run into a problem that bring to > > mind a larger question. > > > > My script uses data from a relational database to pull information about > > external files. The script then displays information from the relational > > database and the contents of the external file. The script then continues > > on the next iteration - each iteration equals one entry in the relational > > database. > > > > If there are 3 or fewer entries in the relational database, the script works > > well. At the fourth entry in the relational database, Apache throws an > > error and the user (me at this point) receives only a generic-type error. > > > > Does anybody have any ideas about how to best go about finding the error? > > Have you checked the apache error log? Where are you seeing this > "generic error message"? > > Note that if you toss in statements like: > > print STDERR "The value is: $value at " . __LINE__ . "\n"; > > That output should show up in the apache error log. > > At a guess, you should look at the data involved more closely: I would > guess there's something in your fourth record that's messing you up, > and you need to be more careful with quoting or using bind parameter > ("?" placeholders) or something like that. > > Try some runs with different data, organized in different ways. > > I also might suggest that at some point you shoule spend some time to > learn how to use the perl debugger, but that admittedly can be a bit > of a pain in a web context. I would second learning the Perl debugger. Its invaluable for quickly getting to the root cause of your problems. I don't think being in a web context really changes much. If its a straight CGI script (not mod_perl) then you can easily run the script in the debugger and supply your own parameters: $ perl -d your_script.cgi DB<1> CGI::param('foo' => 'bar'); Then later in your code, this will work how you expect: my $foo = CGI::param('foo') If you put all your functionality into separate methods, its even easier because you can just call the method with the args you need, and you don't even have to run the whole program: DB<2> s my_method({arg1 => 'someval', arg2 => [1, 2, 3]) where 's' means 'step into'. If you really want/need to run the script directly from a real web request, its possible to start up apache with the perl debugger running and step through requests as they happen. If your using mod_perl, you can still use the debugger, its just a little more complicated if you want to debug calls that involve mod_perl itself. Most of the time though, I don't really need to debug that code. At work we run mod_perl and all our code is in separate Perl modules that I can debug easily and individually outside mod_perl: $ perl -d -e 1 DB<1> use Some::Data::Class DB<2> $res = Some::Data::Class->load_results(type => 'example') DB<3> x $res which starts up the perl debugger in an interactive mode, loads a module, makes a call to a method and then eXamines the results. Garth > You might try to cut down your code the smallest example that reproduces > the problem, then you could post the code here, and we'll look it > over. > > > > _______________________________________________ > SanFrancisco-pm mailing list > SanFrancisco-pm at pm.org > http://mail.pm.org/mailman/listinfo/sanfrancisco-pm > From quinn at fairpath.com Sat Mar 8 13:29:15 2008 From: quinn at fairpath.com (Quinn Weaver) Date: Sat, 8 Mar 2008 13:29:15 -0800 Subject: [sf-perl] Getting Help (was Re: Debugging a CGI script - how) In-Reply-To: <20080308191733.GG23803@fetter.org> References: <000001c88148$f32cff60$d986fe20$@com> <20080308191733.GG23803@fetter.org> Message-ID: <20080308212915.GA62053@fu.funkspiel.org> On Sat, Mar 08, 2008 at 11:17:33AM -0800, David Fetter wrote: > Does anybody have a reference on how to write a good bug report/shout > out for help? Unfortunately, I don't. I'd be interested to know of one and, if someone can find one that looks good enough, I will include it in the metadata (intro email, et cetera) for this list. Meanwhile, for the purposes of this conversation: Neil, we need a lot more detail and code samples if we're going to debug this specific problem. On the other hand, if you just want general tips about debugging Apache scripts (so you can pursue it on your own), Joe's recommendations are spot-on. I'll add that it's possible to connect the Perl debugger to an Apache process. Matt Lanier gave a nice talk on this some years ago. Here are his notes: http://www.lanier.org/~matt/ad-talk/launch-perldb.html Meanwhile, since you're just starting out with Apache and have lots of questions, you should pick up one of the books on the subject. If you're using Apache 1.3.x (as opposed to Apache 2), I highly recommend the mod_perl Developer's Cookbook. It's very well-written, and it's broken up into "recipes" so you can get at exactly what you want (they're self-contained, so that you need little or no prior knowledge to benefit from a given recipe). You can peelk at the table of contents and some samples here: http://www.modperlcookbook.org/ Thanks, -- Quinn Weaver, independent contractor | President, San Francisco Perl Mongers http://fairpath.com/quinn/resume/ | http://sf.pm.org/ 510-520-5217 From quinn at fairpath.com Sat Mar 8 13:44:32 2008 From: quinn at fairpath.com (Quinn Weaver) Date: Sat, 8 Mar 2008 13:44:32 -0800 Subject: [sf-perl] Getting Help (was Re: Debugging a CGI script - how) In-Reply-To: <20080308212915.GA62053@fu.funkspiel.org> References: <000001c88148$f32cff60$d986fe20$@com> <20080308191733.GG23803@fetter.org> <20080308212915.GA62053@fu.funkspiel.org> Message-ID: <20080308214432.GA62111@fu.funkspiel.org> On Sat, Mar 08, 2008 at 01:29:15PM -0800, Quinn Weaver wrote: > On Sat, Mar 08, 2008 at 11:17:33AM -0800, David Fetter wrote: > > > Does anybody have a reference on how to write a good bug report/shout > > out for help? > > Unfortunately, I don't. I'd be interested to know of one and, if > someone can find one that looks good enough, I will include it in the > metadata (intro email, et cetera) for this list. Actually, I decided to write one myself. Here's a first stab. Input is welcome. (I don't promise I'll take all advice, but I'll at least listen. :) ) ******************* If you have some problem code and want to ask a question about it, please: - First try a quick web search (Google or PerlMonks), and consult the standard docs bundled with Perl. It's amazing how many questions are resolved this way. If you do post, please: - Be polite. - Include relevant code snippets, input data, output, and configuration files. Send the smallest bit that you think is relevant, not the whole thing. - Describe the circumstances in which the problem appears, what you've already done to try to diagnose and fix it, and why you're stuck. - Be patient with the speed at which people respond. After all, these are experts who are giving you a free service! Thanks, The San Francisco Perl Mongers staff ******************* -- Quinn Weaver, independent contractor | President, San Francisco Perl Mongers http://fairpath.com/quinn/resume/ | http://sf.pm.org/ 510-520-5217 From quinn at fairpath.com Sat Mar 8 13:46:28 2008 From: quinn at fairpath.com (Quinn Weaver) Date: Sat, 8 Mar 2008 13:46:28 -0800 Subject: [sf-perl] Getting Help (was Re: Debugging a CGI script - how) In-Reply-To: <20080308212915.GA62053@fu.funkspiel.org> References: <000001c88148$f32cff60$d986fe20$@com> <20080308191733.GG23803@fetter.org> <20080308212915.GA62053@fu.funkspiel.org> Message-ID: <20080308214628.GA62147@fu.funkspiel.org> On Sat, Mar 08, 2008 at 01:29:15PM -0800, Quinn Weaver wrote: > I'll add that it's possible to connect the Perl debugger to an Apache > process. Matt Lanier gave a nice talk on this some years ago. > Here are his notes: > http://www.lanier.org/~matt/ad-talk/launch-perldb.html Clarification: this is for mod_perl. For CGI scripts, follow Garth's advice instead. Thanks, -- Quinn Weaver, independent contractor | President, San Francisco Perl Mongers http://fairpath.com/quinn/resume/ | http://sf.pm.org/ 510-520-5217 From doom at kzsu.stanford.edu Sat Mar 8 13:50:30 2008 From: doom at kzsu.stanford.edu (Joe Brenner) Date: Sat, 08 Mar 2008 13:50:30 -0800 Subject: [sf-perl] Getting Help (was Re: Debugging a CGI script - how) In-Reply-To: <200803082043.m28KhBxY048532@kzsu.stanford.edu> References: <000001c88148$f32cff60$d986fe20$@com> <20080308191733.GG23803@fetter.org> <200803082038.m28Kc44f048436@kzsu.stanford.edu> <200803082043.m28KhBxY048532@kzsu.stanford.edu> Message-ID: <200803082150.m28LoUor049603@kzsu.stanford.edu> Joe Brenner wrote: > Joe Brenner wrote: > > > Some projects write their own. There are a few pages on the subject > > written for the emacs documentation: > > > > http://www.gnu.org/software/emacs/manual/html_node/emacs/Bugs.html > > Ah, of course. There's Mark Jason Dominus on the subject: > > http://perl.plover.com/Questions.html And by an amazing coincidence, look what just turned up on the new "official" perl wiki: http://www.perlfoundation.org/perl5/index.cgi?how_to_ask_perl_questions From quinn at fairpath.com Sat Mar 8 14:08:57 2008 From: quinn at fairpath.com (Quinn Weaver) Date: Sat, 8 Mar 2008 14:08:57 -0800 Subject: [sf-perl] Getting Help (was Re: Debugging a CGI script - how) In-Reply-To: <200803082150.m28LoUor049603@kzsu.stanford.edu> References: <000001c88148$f32cff60$d986fe20$@com> <20080308191733.GG23803@fetter.org> <200803082038.m28Kc44f048436@kzsu.stanford.edu> <200803082043.m28KhBxY048532@kzsu.stanford.edu> <200803082150.m28LoUor049603@kzsu.stanford.edu> Message-ID: <20080308220857.GA62339@fu.funkspiel.org> On Sat, Mar 08, 2008 at 01:50:30PM -0800, Joe Brenner wrote: > > Joe Brenner wrote: > > Joe Brenner wrote: > > > > > Some projects write their own. There are a few pages on the subject > > > written for the emacs documentation: > > > > > > http://www.gnu.org/software/emacs/manual/html_node/emacs/Bugs.html > > > > Ah, of course. There's Mark Jason Dominus on the subject: > > > > http://perl.plover.com/Questions.html > > And by an amazing coincidence, look what just turned up on the new > "official" perl wiki: > > http://www.perlfoundation.org/perl5/index.cgi?how_to_ask_perl_questions Nice. Maybe I'll just use that. Meanwhile, here's a stab at the other side of things: ***************** How to answer questions: - Be polite. If someone is rude or out of line, correct them firmly but civilly. - Wherever possible, give people info that empowers them, so they can solve problems on their own. - If you need more information, ask for it. No need to guess what the poster is thinking. - Remember you were once a newbie too. ***************** -- Quinn Weaver, independent contractor | President, San Francisco Perl Mongers http://fairpath.com/quinn/resume/ | http://sf.pm.org/ 510-520-5217 From extasia at extasia.org Sat Mar 8 14:09:46 2008 From: extasia at extasia.org (David Alban) Date: Sat, 8 Mar 2008 14:09:46 -0800 Subject: [sf-perl] Getting Help (was Re: Debugging a CGI script - how) In-Reply-To: <20080308214432.GA62111@fu.funkspiel.org> References: <000001c88148$f32cff60$d986fe20$@com> <20080308191733.GG23803@fetter.org> <20080308212915.GA62053@fu.funkspiel.org> <20080308214432.GA62111@fu.funkspiel.org> Message-ID: <4c714a9c0803081409w5ad72735ta02ed194210b36a7@mail.gmail.com> there's overlap here with what joe wrote below, but also consider... * demonstrate a serious effort on your part before posting your questions (see 'rtfm'); at the very least, have done a web search and have consulted the available documentation (see 'perldoc', 'man', and friends) * specific questions will get much better results than extremely high level / vague / general questions or questions without detail * don't post anything that even appears that you want someone else to do your work for free; note the use of the word "appears"; you may not intend it, but if it appears that you do you will probably not get the information you need * try and come up with the smallest and simplest code that demonstrates your problem (if applicable), you'll get fewer responses if folks have to spend more then five or ten minutes grokking your problem. * if someone cranky flames you, don't respond to the flamey bits. just don't. On Sat, Mar 8, 2008 at 1:44 PM, Quinn Weaver wrote: > If you have some problem code and want to ask a question about it, please: > > - First try a quick web search (Google or PerlMonks), and consult > the standard docs bundled with Perl. It's amazing how many questions > are resolved this way. > > If you do post, please: > > - Be polite. > > - Include relevant code snippets, input data, output, and configuration files. > Send the smallest bit that you think is relevant, not the whole thing. > > - Describe the circumstances in which the problem appears, what you've > already done to try to diagnose and fix it, and why you're stuck. > > - Be patient with the speed at which people respond. After all, these are > experts who are giving you a free service! > > Thanks, > The San Francisco Perl Mongers staff -- Live in a world of your own, but always welcome visitors. From quinn at fairpath.com Sat Mar 8 14:30:43 2008 From: quinn at fairpath.com (Quinn Weaver) Date: Sat, 8 Mar 2008 14:30:43 -0800 Subject: [sf-perl] Getting Help (was Re: Debugging a CGI script - how) In-Reply-To: <4c714a9c0803081409w5ad72735ta02ed194210b36a7@mail.gmail.com> References: <000001c88148$f32cff60$d986fe20$@com> <20080308191733.GG23803@fetter.org> <20080308212915.GA62053@fu.funkspiel.org> <20080308214432.GA62111@fu.funkspiel.org> <4c714a9c0803081409w5ad72735ta02ed194210b36a7@mail.gmail.com> Message-ID: <20080308223043.GA62452@fu.funkspiel.org> On Sat, Mar 08, 2008 at 02:09:46PM -0800, David Alban wrote: > there's overlap here with what joe wrote below, but also consider... This is great. Keep the good ideas coming, everyone, -- Quinn Weaver, independent contractor | President, San Francisco Perl Mongers http://fairpath.com/quinn/resume/ | http://sf.pm.org/ 510-520-5217 From rick at linuxmafia.com Mon Mar 10 03:49:08 2008 From: rick at linuxmafia.com (Rick Moen) Date: Mon, 10 Mar 2008 03:49:08 -0700 Subject: [sf-perl] Getting Help (was Re: Debugging a CGI script - how) In-Reply-To: <20080308191733.GG23803@fetter.org> References: <000001c88148$f32cff60$d986fe20$@com> <20080308191733.GG23803@fetter.org> Message-ID: <20080310104908.GC3420@linuxmafia.com> Quoting David Fetter (david at fetter.org): > I've seen Eric Raymond's smarmy and condescending "How > to Ask Smart Questions".... He had some insufferably smarmy and condescending co-author, too. (Probably a Scandinavian, judging by the guy's surname: My Tante Bjorg always warned me to beware of them.) That essay has become much too verbose and oddly organised: As Tolkien put it, it grew in the telling. I'm aiming at some point to write something a whole lot shorter and punchier, with some sort of much more link-ey and less linear structure. I really rather like the Java Ranch variant, FWIW: http://faq.javaranch.com/java/HowToAskQuestionsOnJavaRanch -- Cheers, "Reality is not optional." Rick Moen -- Thomas Sowell rick at linuxmafia.com From david at fetter.org Mon Mar 10 09:03:03 2008 From: david at fetter.org (David Fetter) Date: Mon, 10 Mar 2008 09:03:03 -0700 Subject: [sf-perl] Getting Help (was Re: Debugging a CGI script - how) In-Reply-To: <20080310104908.GC3420@linuxmafia.com> References: <000001c88148$f32cff60$d986fe20$@com> <20080308191733.GG23803@fetter.org> <20080310104908.GC3420@linuxmafia.com> Message-ID: <20080310160303.GN23803@fetter.org> On Mon, Mar 10, 2008 at 03:49:08AM -0700, Rick Moen wrote: > Quoting David Fetter (david at fetter.org): > > > I've seen Eric Raymond's smarmy and condescending "How to Ask > > Smart Questions".... > > He had some insufferably smarmy and condescending co-author, too. You missed a great chance to let Mr. Raymond take the blame for this one. Very sad, really. > That essay has become much too verbose and oddly organised: Its verbosity is not even in the same league of problem as its authorial voice, which is quite often mistaken for that of a spoiled 14-year-old boy. > As Tolkien put it, it grew in the telling. I'm aiming at some point > to write something a whole lot shorter and punchier, with some sort > of much more link-ey and less linear structure. > > I really rather like the Java Ranch variant, FWIW: > http://faq.javaranch.com/java/HowToAskQuestionsOnJavaRanch The voice of this one (as of this writing) is just great. :) Omnibus thing for potential question askers to consider: http://wooledge.org/mywiki/XyProblem Cheers, David. -- David Fetter http://fetter.org/ Phone: +1 415 235 3778 AIM: dfetter666 Yahoo!: dfetter Skype: davidfetter XMPP: david.fetter at gmail.com Remember to vote! Consider donating to Postgres: http://www.postgresql.org/about/donate From andy at petdance.com Mon Mar 10 09:06:45 2008 From: andy at petdance.com (Andy Lester) Date: Mon, 10 Mar 2008 11:06:45 -0500 Subject: [sf-perl] Getting Help (was Re: Debugging a CGI script - how) In-Reply-To: <20080310160303.GN23803@fetter.org> References: <000001c88148$f32cff60$d986fe20$@com> <20080308191733.GG23803@fetter.org> <20080310104908.GC3420@linuxmafia.com> <20080310160303.GN23803@fetter.org> Message-ID: On Mar 10, 2008, at 11:03 AM, David Fetter wrote: >> I really rather like the Java Ranch variant, FWIW: >> http://faq.javaranch.com/java/HowToAskQuestionsOnJavaRanch > > The voice of this one (as of this writing) is just great. :) That page claims "Do not send Java questions to the authors of these documents! If you do, they will flame you and you will deserve it." That's not correct. No one deserves to be flamed. xoxo, Andy -- Andy Lester => andy at petdance.com => www.petdance.com => AIM:petdance From rick at linuxmafia.com Mon Mar 10 14:48:51 2008 From: rick at linuxmafia.com (Rick Moen) Date: Mon, 10 Mar 2008 14:48:51 -0700 Subject: [sf-perl] Getting Help (was Re: Debugging a CGI script - how) In-Reply-To: <20080310160303.GN23803@fetter.org> References: <000001c88148$f32cff60$d986fe20$@com> <20080308191733.GG23803@fetter.org> <20080310104908.GC3420@linuxmafia.com> <20080310160303.GN23803@fetter.org> Message-ID: <20080310214851.GD3420@linuxmafia.com> Quoting David Fetter (david at fetter.org): > You missed a great chance to let Mr. Raymond take the blame for this > one. Very sad, really. Hmm, I though you knew me better than that, David. I not only never evade responsibility for what I write (or co-write); I insist on it. Particular passages in "How to Ask Questions the Smart Way" still evince very much my own authorial "voice", one quite different from Eric's. In those passages, I aimed to tell readers some blunt, stark, and highly useful, though widely resented and unpalatable, truths. Why? Because I felt my target audience deserved to hear relevant truths as best I could see and tell them. My point? I suspect you'd cordially dislike -- resent -- the parts *I* wrote, too. Oh well; good thing I wasn't trying to win any popularity contests, just tell my intended audience what they needed to know. Here's an example: Describe the problem's symptoms, not your guesses It's not useful to say what you think is causing your problem. (If your diagnostic theories were such hot stuff, would you be consulting others for help?) So, make sure you're listing the raw symptoms of what goes wrong, rather than your interpretations and theories. Let your helpers do the interpretation and diagnosis. [snip examples of good and bad descriptions] Since the preceding point seems to be a tough one for many people to grasp, here's a phrase to remind you: "All diagnosticians are from Missouri." That US state's official motto is "Show me" (earned in 1899, when Congressman Willard D. Vandiver said "I come from a country that raises corn and cotton and cockleburs and Democrats, and frothy eloquence neither convinces nor satisfies me. I'm from Missouri. You've got to show me.") In diagnosticians' case, it's not a matter of skepticism, but rather a literal, functional need to see whatever is as close as possible to the same raw evidence that you see, rather than your surmises and summaries. Show us. I've backed out Eric's reference to "hackers", which was his patch: My own target audience, when I started my own version of the essay (but then found out that Eric was attempting approximately the same essay, and we joined forces) was technical users who seem to wish to understand, to learn, be competent, and _maybe teach others_ later on -- as opposed to merely wanting a free helpdesk. Which in part repays my own debt, to earlier people who tried to give me clue. Nothing against people willing to serve as free helpdesks for endless poorly thought out questions from net.random querents who are fundamentally unwilling to learn. I admire the former's saintliness, and hope they have endurance to match their benevolence. From quinn at fairpath.com Mon Mar 10 16:11:53 2008 From: quinn at fairpath.com (Quinn Weaver) Date: Mon, 10 Mar 2008 15:11:53 -0800 Subject: [sf-perl] Getting Help (was Re: Debugging a CGI script - how) In-Reply-To: <20080310214851.GD3420@linuxmafia.com> References: <000001c88148$f32cff60$d986fe20$@com> <20080308191733.GG23803@fetter.org> <20080310104908.GC3420@linuxmafia.com> <20080310160303.GN23803@fetter.org> <20080310214851.GD3420@linuxmafia.com> Message-ID: <20080310231153.GA83912@fu.funkspiel.org> Hi, guys, list mom here. Just a gentle pre-emptive request: can we please keep this thread on etiquette from turning into an actual argument? :) It's certainly not a flame war yet, but my Jedi senses detect some potential rumors of war. Please keep your cool, but please also consider when to just let the matter go. Every time there's a long thread about who is right, several people unsubscribe for good. Thanks, -- Quinn Weaver, independent contractor | President, San Francisco Perl Mongers http://fairpath.com/quinn/resume/ | http://sf.pm.org/ 510-520-5217 From doom at kzsu.stanford.edu Mon Mar 10 23:52:46 2008 From: doom at kzsu.stanford.edu (Joe Brenner) Date: Mon, 10 Mar 2008 23:52:46 -0700 Subject: [sf-perl] Getting Help (was Re: Debugging a CGI script - how) In-Reply-To: <20080310231153.GA83912@fu.funkspiel.org> References: <000001c88148$f32cff60$d986fe20$@com> <20080308191733.GG23803@fetter.org> <20080310104908.GC3420@linuxmafia.com> <20080310160303.GN23803@fetter.org> <20080310214851.GD3420@linuxmafia.com> <20080310231153.GA83912@fu.funkspiel.org> Message-ID: <200803110652.m2B6qkT0090638@kzsu.stanford.edu> Quinn Weaver wrote: > Hi, guys, list mom here. Just a gentle pre-emptive request: can we > please keep this thread on etiquette from turning into an actual > argument? :) You may have heard me coming. I wanted to point out that the "Be polite" rule is a local rule, not necessarily a universal principle, and other forums have the right to choose differently. The other approach is to focus on the other side: "Grow some skin, try to rise above insult, listen for what's useful to you, and skip what isn't." From quinn at fairpath.com Tue Mar 11 12:32:24 2008 From: quinn at fairpath.com (Quinn Weaver) Date: Tue, 11 Mar 2008 11:32:24 -0800 Subject: [sf-perl] Lugradio conference at the Metreon Message-ID: <20080311193224.GA94624@fu.funkspiel.org> Wow. LugRadio is putting on a Linux/open-source conference April 12 and 13 at the Metreon. Registration is $10 - Google and Dice are picking up most of the tab. They have an impressive list of speakers. It's funny, just yesterday I was mailing Fred about LinuxWorld preparation (I want to get started now; it's in August). One month is a pretty tight schedule, but we could pull off a booth for LugRadio iff we get enough boothies. The conference is on a weekend--is anyone up to helping? I need as many people as possible to run four-hour shifts; we need two people at the booth at any given time. So that's probably eight slots to fill, total. Call it ten, in case someone needs to cancel at the last minute. Are people up for this? I don't want to be half-assed about this, but if we can get enough people I'm all for it. ----- Forwarded message from George Woolley ----- From: George Woolley Date: Mon, 10 Mar 2008 19:04:29 -0800 To: Oakland Perl Mongers Subject: [oak perl] Fwd: Perl at LugRadio Live USA 2008 in San Francisco ---------- Forwarded Message ---------- Subject: Perl at LugRadio Live USA 2008 in San Francisco Date: Monday 10 March 2008 17:10 From: LugRadio ... Hi, I just wanted to drop you a quick note about a community organised and run Open Source and technology event that we have been working on that your group may be interested in. It is called LugRadio Live USA 2008 and has over 35 well-known speakers, nearly 40 exhibitors and takes place on the 12th and 13th April 2008 in San Francisco. It is very much a community event, and designed for the community - we have been working on it for the last six months or so with a large number of volunteers. To make it as accessible as possible for people, we don't believe in charging the $600-$1200 that other commercial shows do - our show is just $10 for the full weekend. We figured your group may be interested in LugRadio Live USA 2008, and would love to see you there (we also have exhibition space available if you would like to exhibit your group - it is free to exhibit!). Anyway, below is the announcement of the show, if you could pass it onto your members, that would be great. :) -------- LugRadio Live USA 2008 12th and 13th April 2008 The Metreon, 101 4th St., San Francisco, CA, 94103 Registration for LugRadio Live USA 2008 is now open at http://lugradio.org/live/USA2008/register, and tickets for the two-day spectacular cost only $10 for the full weekend, including full access to all talks, the exhibition, evening events, and a free bag o'swag for visitors. Pre-registrations also enjoy additional benefits at the show and the first 50 registrations will receive a free copy of Postal 2: Share The Pain (subject to age verification), thanks to Running With Scissors. All pre-registrations will also be entered into a raffle to win prizes by a variety of vendors. LugRadio Live USA 2008, the 'rock-conference' from the team behind the popular LugRadio podcast (http://www.lugradio.org), brings the successful and unique formula of the UK LugRadio Live events to The Metreon in San Francisco on the 12th and 13th April 2008. The event is supported extensively by Google and also supported by Dice. LinuxQuestions.org is a press partner. LugRadio Live USA 2008 brings together over 35 speakers across three stages, 30+ exhibitors, a range of BOF sessions, debate panels, lightbulb talk sessions, demos and much more, all wrapped up in the unique event that the UK incarnation has become known for, combining an incredibly loose, social, inclusive, and amusing atmosphere - if you are new to LugRadio Live, it is nothing you will have seen before. Confirmed speakers for the event include: * Miguel de Icaza (Mono / Novell / Co-Founder Of GNOME) * Ian Murdoch (OpenSolaris / Founder Of Debian) * Robert Love (GNOME / Google) * Aza Raskin (Mozilla / Humanized) * Benjamin Mako Hill (Ubuntu / Debian / FSF) * John Buckman (Magnatune) * Val Henson (Kernel / VAH consulting) * Christopher Blizzard (Mozilla / GNOME) * Mike Linksvayer (Creative Commons) * Alex Graveley (VMWare / GNOME) * David Schleef (GStreamer) * Matthew Garrett (Power Management / Kernel) * Danese Cooper (Intel / OSI) * Aaron Bockover (Banshee / Novell) * Liana Holmberg (Second Life / Linden Lab) * Emma Jane Hogbin (Hick Tech) * Joe Zonker Brockmeier (OpenSuSE / Novell) * Kristen Accardi (Kernel) * David Lefty Schlesinger * Joe Born (Neuros) * Selena Deckelmann (PostgreSQL) * Stewart Smith (MySQL) * Dan Kegal (Wine) * Ben Collins (Ubuntu / Kernel) * Jason Kridner (Texas Instruments) * Jeremy Allison (Samba / Google) * Christian Hammond (VMWare) * Ian McKeller (Songbird) * Alison Randall (Parrot / Perl / OSCON) * David Huffman (LVM) * Brian Will (Pigeon) * Belinda Lopez (Ubuntu) * Ilan Rabanovich (SoCal Linux Expo) * Eddy Mulyono (Packaging) * Matthew Walster (Demo Scene) The show will also involve a large exhibition area with a range of projects, organisations and companies with plenty to see and do. The first batch of confirmed exhibitors (at the show there will be another twice as many exhibitors) include: * Google * Dice * GNOME * PostgreSQL * O'Reilly * OpenSuSE * Linden Labs * Magnatune * gOS * Neuros * Sun * Texas Instruments * South California Linux Expo * Komputers 4 R Kids * San Francisco LUG * BytesFree.org * Ontario Linux Fest * Frets on Fire * OpenNMS * One Course Source * Haiku * Hyperic * BitRock * Ubuntu * OpenStreetMap * The Digital Tipping Point * FreeBSD * Inkscape In addition to this, the LugRadio team will be recording a live performance of their cult-hit podcast, which has over 20,000 listeners, in front of the LugRadio Live USA 2008 audience - like the UK event, this is always quite a spectacle, and excellent fun for all involved. More information about LugRadio Live USA 2008 can be found at http://lugradio.org/live/USA2008/ -------- Thanks! Jono and the LugRadio Live USA 2008 team ------------------------------------------------------- _______________________________________________ Oakland mailing list Oakland at pm.org http://mail.pm.org/mailman/listinfo/oakland ----- End forwarded message ----- -- Quinn Weaver, independent contractor | President, San Francisco Perl Mongers http://fairpath.com/quinn/resume/ | http://sf.pm.org/ 510-520-5217 From quinn at fairpath.com Tue Mar 11 12:52:02 2008 From: quinn at fairpath.com (Quinn Weaver) Date: Tue, 11 Mar 2008 11:52:02 -0800 Subject: [sf-perl] Lugradio conference at the Metreon In-Reply-To: <20080311193224.GA94624@fu.funkspiel.org> References: <20080311193224.GA94624@fu.funkspiel.org> Message-ID: <20080311195201.GC94624@fu.funkspiel.org> On Tue, Mar 11, 2008 at 11:32:24AM -0800, Quinn Weaver wrote: > Are people up for this? I don't want to be half-assed about this, but > if we can get enough people I'm all for it. And my commitment: I'll work two slots, but I'd like to keep the other two open to attend talks. May add a slot once the talk schedule is published. -- Quinn Weaver, independent contractor | President, San Francisco Perl Mongers http://fairpath.com/quinn/resume/ | http://sf.pm.org/ 510-520-5217 From fred at redhotpenguin.com Tue Mar 11 14:08:09 2008 From: fred at redhotpenguin.com (Fred Moyer) Date: Tue, 11 Mar 2008 14:08:09 -0700 Subject: [sf-perl] Lugradio conference at the Metreon In-Reply-To: <20080311195201.GC94624@fu.funkspiel.org> References: <20080311193224.GA94624@fu.funkspiel.org> <20080311195201.GC94624@fu.funkspiel.org> Message-ID: <47D6F4B9.9060001@redhotpenguin.com> Quinn Weaver wrote: > On Tue, Mar 11, 2008 at 11:32:24AM -0800, Quinn Weaver wrote: > >> Are people up for this? I don't want to be half-assed about this, but >> if we can get enough people I'm all for it. > > And my commitment: I'll work two slots, but I'd like to keep the other > two open to attend talks. May add a slot once the talk schedule is > published. Yeah, I'll take a couple slots - there is somewhere to plug a laptop in right? :) From doom at kzsu.stanford.edu Tue Mar 11 17:01:04 2008 From: doom at kzsu.stanford.edu (Joe Brenner) Date: Tue, 11 Mar 2008 17:01:04 -0700 Subject: [sf-perl] Lugradio conference at the Metreon In-Reply-To: <20080311193224.GA94624@fu.funkspiel.org> References: <20080311193224.GA94624@fu.funkspiel.org> Message-ID: <200803120001.m2C014YF005605@kzsu.stanford.edu> Quinn Weaver wrote: > Wow. LugRadio is putting on a Linux/open-source conference April 12 and 13 > at the Metreon. Registration is $10 - Google and Dice are picking up > most of the tab. They have an impressive list of speakers. > > It's funny, just yesterday I was mailing Fred about LinuxWorld > preparation (I want to get started now; it's in August). > > One month is a pretty tight schedule, but we could pull off a booth > for LugRadio iff we get enough boothies. The conference is on a > weekend--is anyone up to helping? I need as many people as possible > to run four-hour shifts; we need two people at the booth at any > given time. So that's probably eight slots to fill, total. > Call it ten, in case someone needs to cancel at the last minute. I can take at least two. (Has anyone heard anything from the codecon folks? Their web site is seems a little too inactive for an event that's really happening. I tried shooting them some email, but got no response.) From quinn at fairpath.com Tue Mar 11 18:23:46 2008 From: quinn at fairpath.com (Quinn Weaver) Date: Tue, 11 Mar 2008 17:23:46 -0800 Subject: [sf-perl] Lugradio conference at the Metreon In-Reply-To: <200803120001.m2C014YF005605@kzsu.stanford.edu> References: <20080311193224.GA94624@fu.funkspiel.org> <200803120001.m2C014YF005605@kzsu.stanford.edu> Message-ID: <20080312012346.GB96056@fu.funkspiel.org> On Tue, Mar 11, 2008 at 05:01:04PM -0700, Joe Brenner wrote: > (Has anyone heard anything from the codecon folks? Their web site is > seems a little too inactive for an event that's really happening. > I tried shooting them some email, but got no response.) I'm on their announce list, but I haven't seen anything. -- Quinn Weaver, independent contractor | President, San Francisco Perl Mongers http://fairpath.com/quinn/resume/ | http://sf.pm.org/ 510-520-5217 From josh at agliodbs.com Tue Mar 11 19:29:01 2008 From: josh at agliodbs.com (Josh Berkus) Date: Tue, 11 Mar 2008 19:29:01 -0700 Subject: [sf-perl] Lugradio conference at the Metreon In-Reply-To: <200803120001.m2C014YF005605@kzsu.stanford.edu> References: <20080311193224.GA94624@fu.funkspiel.org> <200803120001.m2C014YF005605@kzsu.stanford.edu> Message-ID: <47D73FED.5090500@agliodbs.com> Joe, Quinn, I think PostgresQL will have a booth at LugRadio. --Josh From quinn at fairpath.com Wed Mar 12 09:20:40 2008 From: quinn at fairpath.com (Quinn Weaver) Date: Wed, 12 Mar 2008 08:20:40 -0800 Subject: [sf-perl] Lugradio conference at the Metreon In-Reply-To: <47D73FED.5090500@agliodbs.com> References: <20080311193224.GA94624@fu.funkspiel.org> <200803120001.m2C014YF005605@kzsu.stanford.edu> <47D73FED.5090500@agliodbs.com> Message-ID: <20080312162040.GA5051@fu.funkspiel.org> On Tue, Mar 11, 2008 at 07:29:01PM -0700, Josh Berkus wrote: > Joe, Quinn, > > I think PostgresQL will have a booth at LugRadio. Excellent. For those keeping score at home: I have just under a week to apply for the booth. We have ~6 slots taken care of, so that means we need just 4 more filled to meet our minimum. (Reminder: a slot is a four-hour commitment to hang out at the booth, with at least one other person. This is either Saturday or Sunday, April 12 or 13, during the day.) So, if we can get four more people to work one shift apiece, or two more people to work two shifts apiece, we're home-free. And we can get on to signage, literature, etc., which we'll have a month to handle. Volunteers? -- Quinn Weaver, independent contractor | President, San Francisco Perl Mongers http://fairpath.com/quinn/resume/ | http://sf.pm.org/ 510-520-5217 From rdm at cfcl.com Wed Mar 12 22:08:43 2008 From: rdm at cfcl.com (Rich Morin) Date: Wed, 12 Mar 2008 21:08:43 -0800 Subject: [sf-perl] Fwd: [BALUG-Talk] March 15 OLPC meet at SF State Message-ID: This could be fun... -r --- Begin Forward --- Date: Wed, 12 Mar 2008 12:11:13 -0700 From: Sameer Verma To: balug-talk-balug.org at lists.balug.org Subject: [BALUG-Talk] March 15 OLPC meet at SF State Note: Also on the web at http://opensource.sfsu.edu/node/479 Calling all San Francisco Bay Area OLPC enthusiasts! If you have an XO laptop, or are just interested in seeing how they work, come on down to SF State campus for a get together on March 15, 2008. If you have an XO or two (or ten), bring them! It is after all St. Patrick's Day and the XO is very green indeed! Don't have an XO? Download a LiveCD from http://dev.laptop.org/pub/livebackupcd/ or simply bring your enthusiasm. What: OLPC meet at San Francisco State University Why: Build a mesh network, share activities, generate crazy ideas. You can sit around the campus (we are not that large) and mesh up with others. How far will the mesh go? Only one way to find out! Bring a jacket if you plan on sitting outdoors. This is, after all, San Francisco weather! When: Saturday, March 15, 2008 from 10am to 2pm Where: Business Bldg. 202, SF State main campus (1600 Holloway Ave. San Francisco, CA 94132). Map: http://www.sfsu.edu/~sfsumap/ By car: http://www.sfsu.edu/~parking/directions/main_campus/car.html By Muni: http://www.sfsu.edu/~parking/directions/main_campus/muni.html Who: Sponsored by IMSA Student Association (http://imsa.sfsu.edu/). Sameer -- Dr. Sameer Verma, Ph.D. Associate Professor of Information Systems San Francisco State University San Francisco CA 94132 USA http://verma.sfsu.edu/ http://opensource.sfsu.edu/ _______________________________________________ BALUG-Talk mailing list BALUG-Talk at lists.balug.org http://lists.balug.org/listinfo.cgi/balug-talk-balug.org --- End Forward --- -- http://www.cfcl.com/rdm Rich Morin http://www.cfcl.com/rdm/resume rdm at cfcl.com http://www.cfcl.com/rdm/weblog +1 650-873-7841 Technical editing and writing, programming, and web development From duane.obrien at gmail.com Wed Mar 12 21:23:54 2008 From: duane.obrien at gmail.com (Duane Obrien) Date: Wed, 12 Mar 2008 21:23:54 -0700 Subject: [sf-perl] Fwd: [BALUG-Talk] March 15 OLPC meet at SF State In-Reply-To: References: Message-ID: I'd love to go. If mine ever got here. I'm one of those guys who fell through the cracks and won't get theirs until next week at the earliest. has anyone else on list gotten one? On Wed, Mar 12, 2008 at 10:08 PM, Rich Morin wrote: > This could be fun... > > -r > > > --- Begin Forward --- > > Date: Wed, 12 Mar 2008 12:11:13 -0700 > From: Sameer Verma > To: balug-talk-balug.org at lists.balug.org > Subject: [BALUG-Talk] March 15 OLPC meet at SF State > > Note: Also on the web at http://opensource.sfsu.edu/node/479 > > Calling all San Francisco Bay Area OLPC enthusiasts! > > If you have an XO laptop, or are just interested in seeing how they > work, come on down to SF State campus for a get together on March 15, > 2008. If you have an XO or two (or ten), bring them! It is after all St. > Patrick's Day and the XO is very green indeed! > > Don't have an XO? Download a LiveCD from > http://dev.laptop.org/pub/livebackupcd/ or simply bring your enthusiasm. > > What: OLPC meet at San Francisco State University > > Why: Build a mesh network, share activities, generate crazy ideas. You > can sit around the campus (we are not that large) and mesh up with > others. How far will the mesh go? Only one way to find out! Bring a > jacket if you plan on sitting outdoors. This is, after all, San > Francisco weather! > > When: Saturday, March 15, 2008 from 10am to 2pm > > Where: Business Bldg. 202, SF State main campus (1600 Holloway Ave. San > Francisco, CA 94132). > > Map: http://www.sfsu.edu/~sfsumap/ > > By car: http://www.sfsu.edu/~parking/directions/main_campus/car.html > > By Muni: http://www.sfsu.edu/~parking/directions/main_campus/muni.html > > Who: Sponsored by IMSA Student Association (http://imsa.sfsu.edu/). > > > Sameer > > -- > Dr. Sameer Verma, Ph.D. > Associate Professor of Information Systems > San Francisco State University > San Francisco CA 94132 USA > http://verma.sfsu.edu/ > http://opensource.sfsu.edu/ > > _______________________________________________ > BALUG-Talk mailing list > BALUG-Talk at lists.balug.org > http://lists.balug.org/listinfo.cgi/balug-talk-balug.org > > --- End Forward --- > > -- > http://www.cfcl.com/rdm Rich Morin > http://www.cfcl.com/rdm/resume rdm at cfcl.com > http://www.cfcl.com/rdm/weblog +1 650-873-7841 > > Technical editing and writing, programming, and web development > _______________________________________________ > SanFrancisco-pm mailing list > SanFrancisco-pm at pm.org > http://mail.pm.org/mailman/listinfo/sanfrancisco-pm > -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Don't ever tell anybody anything. If you do, you start missing everybody. From rdm at cfcl.com Wed Mar 12 22:38:23 2008 From: rdm at cfcl.com (Rich Morin) Date: Wed, 12 Mar 2008 21:38:23 -0800 Subject: [sf-perl] Fwd: [BALUG-Talk] March 15 OLPC meet at SF State In-Reply-To: References: Message-ID: At 21:23 -0700 3/12/08, Duane Obrien wrote: > has anyone else on list gotten one? V& I and got ours a while back. We tend to bring it to BASS and other XO owners have been showing up with them. http://cfcl.com/rdm/bass/ -r -- http://www.cfcl.com/rdm Rich Morin http://www.cfcl.com/rdm/resume rdm at cfcl.com http://www.cfcl.com/rdm/weblog +1 650-873-7841 Technical editing and writing, programming, and web development From matisse at matisse.net Thu Mar 13 10:52:55 2008 From: matisse at matisse.net (Matisse Enzer) Date: Thu, 13 Mar 2008 10:52:55 -0700 Subject: [sf-perl] Can't figure this one out In-Reply-To: <1602.66.93.171.131.1204760811.squirrel@webmail.silcon.com> References: <1602.66.93.171.131.1204760811.squirrel@webmail.silcon.com> Message-ID: On Mar 5, 2008, at 3:46 PM, nheller at silcon.com wrote: > > if ($action =~ /start/i) { <-------- line 511, the offender > &MainPage($q, \%p); > } > elsif ($action =~ /new/i || > $action =~ /del/i || > $action =~ /edt/i || > $action =~ /save/i ) > { > > I wonder if you should also change this to: my $main_sub = sub { MainPage( $q,\%p }; my $other_sub = sub { do_stuff( @_ ) }; my %dispatch_to = ( start => $main_sub, new => $other_sub, del => $other_sub, edit => $other_sub, save => $other_sub, ); my $lower_case_action = lc $action; my $dispatch_sub = $dispatch_to{ $lower_case_action }; $dispatch_sub->( @other_args_can_go_here ); ------------------------------------------------------- Matisse Enzer http://www.matisse.net/ - http://www.eigenstate.net/ From biztos at mac.com Thu Mar 13 11:27:27 2008 From: biztos at mac.com (frosty) Date: Thu, 13 Mar 2008 11:27:27 -0700 Subject: [sf-perl] Can't figure this one out In-Reply-To: References: <1602.66.93.171.131.1204760811.squirrel@webmail.silcon.com> Message-ID: <1D3EC9A8-0118-1000-8774-5664DAB756B9-Webmail-10021@mac.com> ...or even: my $main_sub = sub { MainPage( $q,\%p ) }; ;-) -- frosty On Thursday, March 13, 2008, at 10:53AM, "Matisse Enzer" wrote: >I wonder if you should also change this to: > > my $main_sub = sub { MainPage( $q,\%p }; > ...etc... From rdm at cfcl.com Thu Mar 13 19:20:02 2008 From: rdm at cfcl.com (Rich Morin) Date: Thu, 13 Mar 2008 18:20:02 -0800 Subject: [sf-perl] Fwd: [BALUG-Announce] Mark Shuttleworth at BALUG 2008-03-25!, and other BALUG News Message-ID: I realize this falls on top of the normal SFPUG evening, but I don't get a chance to hear Mark Shuttleworth very often. Hmmmm; anyone want to have an SFPUG table at the dinner? -r --- Begin Forward --- Date: Thu, 13 Mar 2008 07:34:26 -0700 From: Michael Paoli To: balug-announce at lists.balug.org Subject: [BALUG-Announce] Mark Shuttleworth at BALUG 2008-03-25!, and other BALUG News Mark Shuttleworth at BALUG 2008-03-25!, and other BALUG News Contents: * Mark Shuttleworth at BALUG 2008-03-25 (note change from usual date) * Additional upcoming BALUG meeting dates and speakers * LugRadio Live USA 2008 in San Francisco * Contacts, etc. ------------------------------ Mark Shuttleworth at BALUG 2008-03-25 (note change from usual date) NOTE SPECIAL MEETING DATE: 2008-03-25 (no meeting on 2008-03-18) For our 2008-03-25 meeting we are proud to present: Mark Shuttleworth[1] of Ubuntu[2]/Canonical[3]. Mark is founder of the Ubuntu Project[2], and also founded Thawte[4] (which specialized in digital certificates), HBD Venture Capital[5] (invests in early stage South African companies with high growth potential) and The Shuttleworth Foundation[6] (non-profit organization that accelerates social innovation in Africa with a particular focus on education), and also formed Canonical[3] (commercial sponsor of Ubuntu, and committed to the development, distribution and promotion of open source software products, and to providing tools and support to the open source community). In April 2002, Mark also became the First African in Space[7], arriving via Soyuz TM-34 to the International Space Station and spending several days there, and returning via Soyuz TM-33. If you intend to come, please RSVP to: rsvp at balug.org Why RSVP? Well, we probably wouldn't turn you away, but the RSVPs really help the Four Seas Restaurant plan settings/food/staffing and help ensure that we're able to eat upstairs in the private banquet room. Subscribe to our (low volume) Announce list[8] to be sure and be notified of our upcoming events. 1. http://www.markshuttleworth.com/biography 2. http://www.ubuntu.com/ 3. http://www.canonical.com/ 4. http://www.thawte.com/ 5. http://www.hbd.com/ 6. http://www.shuttleworthfoundation.org/ 7. http://www.africaninspace.com/ 8. http://www.new.balug.org/#Lists ------------------------------ Additional upcoming BALUG meeting dates[9] and speakers (see our web page[9] for more details): 2008-04-15 Eric Allman 2008-05-20 Jeremy Allison 2008-06-17 Andrew Morton 2008-07-15 Mike Linksvayer, CTO, Creative Commons Subscribe to our (quite low volume) Announce list[8] to be sure and be notified of our upcoming events. 8. http://www.new.balug.org/#Lists 9. http://www.new.balug.org/#Meetings%20(upcoming) ------------------------------ LugRadio Live USA 2008[10] at The Metreon in San Francisco, April 12th & 13th, 2008 LugRadio Live USA 2008 brings San Francisco the unique atmosphere of LugRadio Live UK, an event that has developed a strong reputation for providing a range of topics about free software, Open Source, digital rights, technology and more, a compelling list of speakers, exhibitors and birds of a feather sessions, and wrapping it all in a unique, fun, loose, social and inclusive event, which is often described as combining the atmosphere of a rock concert and a computer conference. BALUG may also be participating in this - along with other User Groups in the area. 10. http://www.lugradio.org/live/USA2008/ ------------------------------ Contacting BALUG: http://www.new.balug.org/#Contact Feedback on our publicity/announcements (e.g. contacts or lists where we should get our information out that we're not presently reaching, or things we should do differently): publicity-feedback at balug.org _______________________________________________ BALUG-Announce mailing list BALUG-Announce at lists.balug.org http://lists.balug.org/listinfo.cgi/balug-announce-balug.org --- End Forward --- -- http://www.cfcl.com/rdm Rich Morin http://www.cfcl.com/rdm/resume rdm at cfcl.com http://www.cfcl.com/rdm/weblog +1 650-873-7841 Technical editing and writing, programming, and web development From quinn at fairpath.com Thu Mar 13 18:35:30 2008 From: quinn at fairpath.com (Quinn Weaver) Date: Thu, 13 Mar 2008 17:35:30 -0800 Subject: [sf-perl] Fwd: [BALUG-Announce] Mark Shuttleworth at BALUG 2008-03-25!, and other BALUG News In-Reply-To: References: Message-ID: <20080314013530.GB20761@fu.funkspiel.org> On Thu, Mar 13, 2008 at 06:20:02PM -0800, Rich Morin wrote: > I realize this falls on top of the normal SFPUG evening, > but I don't get a chance to hear Mark Shuttleworth very > often. Hmmmm; anyone want to have an SFPUG table at the > dinner? Absolutely. And this is a good stand-in, IMO, for a March meeting. I have a meeting in the works for April 22, by the way. Details to follow when stuff in confirmed. -- Quinn Weaver, independent contractor | President, San Francisco Perl Mongers http://fairpath.com/quinn/resume/ | http://sf.pm.org/ 510-520-5217 From afife at untangle.com Fri Mar 14 12:26:26 2008 From: afife at untangle.com (Andrew Fife) Date: Fri, 14 Mar 2008 12:26:26 -0700 (PDT) Subject: [sf-perl] Fwd: [BALUG-Announce] Mark Shuttleworth at BALUG In-Reply-To: References: Message-ID: <006d01c88609$669249f0$0200a8c0@Untangle.local> >Hmmmm; anyone want to have an SFPUG table at the >dinner? I'd be happy to setup a SFPM table, just remember to bring a placard so that everyone knows where it is. Incidentally, the Sonoma PM group is also making the Shuttleworth event their March Meeting. ---------------------------------------- Andrew Fife Untangle - Open Source Security Gateway download.untangle.com 650.425.3327 (O) 415.806.6028 (C) afife at untangle.com From extasia at extasia.org Fri Mar 14 19:38:47 2008 From: extasia at extasia.org (David Alban) Date: Fri, 14 Mar 2008 19:38:47 -0700 Subject: [sf-perl] parallelize system tasks, collecting statuses and output Message-ID: <4c714a9c0803141938o327847d7gc7419856c45a1514@mail.gmail.com> greetings, our sysadmins regularly need to restart a service on, say thirty machines. the service takes two and a half minutes to restart. i'd like to write a perl program they can use to parallelize the restart. so that the whole operation takes three minutes rather than an hour or more. i want to collect the statuses and any output of the service restart commands. i found the Bidirectional Communication with Yourself section of the perlipc man page. i'm trying to hack their example so that only the child writer writes to the parent reader. my hacked version forks two child processes, which i want to run in parallel. each child process ssh's to a host, sleeps a small amount of time, and then runs the hostname command. but the child procs seem to be running serially. #!/usr/bin/perl use warnings; use strict; # log_timestamp() below comes from this module use ; use IO::Handle; my @hosts = qw( hostname_1 hostname_2 ); my $numprocs = @hosts; my @output; for my $instance ( 1..$numprocs ) { my $index = $instance - 1; pipe( CHILD_READER, PARENT_WRITER ) or die "can't pipe( CHILD_READER, PARENT_WRITER ): $!\n"; PARENT_WRITER->autoflush( 1 ); my $pid; # parent if ( $pid = fork() ) { close PARENT_WRITER; chomp( my $line = ); $output[ $index ] = $line; close CHILD_READER; } # if # child else { not defined $pid and die "can't fork: $!\n"; close CHILD_READER; my $host = $hosts[ $index ]; my @results = qx{ ssh $host "sleep 5; hostname" }; print PARENT_WRITER log_timestamp(), " child pid $$; instance $instance; results => ", join( '', @results ); close PARENT_WRITER; exit; } # if } # for for my $instance ( 1..$numprocs ) { my $index = $instance - 1; print $output[ $index ], "\n"; } # if -------------------------------------------------------------------------------- i execute this as: $ date; perl junk; date and get: Sat Mar 15 02:30:22 UTC 2008 2008-03-15 02:30:27 +0000 child pid 5469; instance 1; results => hostname_1 2008-03-15 02:30:32 +0000 child pid 5471; instance 2; results => hostname_2 Sat Mar 15 02:30:32 UTC 2008 it's running the second child process only after the first one finishes, which defeats my goal of parallelizing. what am i missing? there's so much stuff out there that promises to help with this and i don't know whether i'm going down the wrong path. surely you fine folks must have done stuff like this before. do indeed tell me to rtfm, but please tell me which fm (or other doc) to r. please also feel free to tell me i'm going about it totally the wrong way, perhaps with a pointer in the general (better) direction. thanks, david -- Live in a world of your own, but always welcome visitors. From friedman at highwire.stanford.edu Fri Mar 14 22:12:09 2008 From: friedman at highwire.stanford.edu (Michael Friedman) Date: Fri, 14 Mar 2008 22:12:09 -0700 Subject: [sf-perl] parallelize system tasks, collecting statuses and output In-Reply-To: <4c714a9c0803141938o327847d7gc7419856c45a1514@mail.gmail.com> References: <4c714a9c0803141938o327847d7gc7419856c45a1514@mail.gmail.com> Message-ID: <0D87E766-1BEC-4A0A-A6FD-2C2F43E7B674@highwire.stanford.edu> David, I think the sequentialism is in your code. You fork() in a loop, and each child does its thing, but the parent process -- the one that is about to fork the next child -- is sitting there waiting on the child's output: chomp( my $line = ); Until the child gives it something, you've got blocking IO there. It won't start the next child until after it's received the output from the previous child. To make it actually parallel, you have to not wait on output from the child until after you've created all the children. You can do that via a double-fork server, some sort of signaling, or... Have you considered using threads? Perl now comes with real live working thread support (if you compiled it in). The threads API is pretty brilliant, IMO, as it makes it almost as easy as in Java to write multi-threaded code. http://search.cpan.org/~jdhedden/threads-1.69/threads.pm If you didn't happen to compile in thread support, or are running on someone else's copy of perl who didn't, there's a CPAN module that emulates the thread API using fork(). It's much slower than real threads, but lets you write code that works without threads now and with them later when you can update perl. http://search.cpan.org/~rybskej/forks-0.27/lib/forks.pm In either case, it explicitly lets you detach from threads and let them run at their own pace, gathering the results later. Your driving script can only pick up the results in single file, but threads may finish in a different order than you started them. I've used this a couple of times and it's pretty cool. ;-) I think the threads API would be a good solution to your problem, if it's available to you. -- Mike On Mar 14, 2008, at 7:38 PM, David Alban wrote: > greetings, > > our sysadmins regularly need to restart a service on, say thirty > machines. the service takes two and a half minutes to restart. i'd > like to write a perl program they can use to parallelize the restart. > so that the whole operation takes three minutes rather than an hour or > more. i want to collect the statuses and any output of the service > restart commands. > > i found the Bidirectional Communication with Yourself section of the > perlipc man page. i'm trying to hack their example so that only the > child writer writes to the parent reader. my hacked version forks two > child processes, which i want to run in parallel. each child process > ssh's to a host, sleeps a small amount of time, and then runs the > hostname command. but the child procs seem to be running serially. > > #!/usr/bin/perl > > use warnings; > use strict; > > # log_timestamp() below comes from this module > use ; > > use IO::Handle; > > my @hosts = qw( hostname_1 hostname_2 ); > my $numprocs = @hosts; > > my @output; > > for my $instance ( 1..$numprocs ) { > my $index = $instance - 1; > > pipe( CHILD_READER, PARENT_WRITER ) > or die "can't pipe( CHILD_READER, PARENT_WRITER ): $!\n"; > > PARENT_WRITER->autoflush( 1 ); > > my $pid; > > # parent > if ( $pid = fork() ) { > close PARENT_WRITER; > > chomp( my $line = ); > $output[ $index ] = $line; > > close CHILD_READER; > } # if > > # child > else { > not defined $pid and die "can't fork: $!\n"; > > close CHILD_READER; > > my $host = $hosts[ $index ]; > my @results = qx{ ssh $host "sleep 5; hostname" }; > > print PARENT_WRITER > log_timestamp(), > " child pid $$; instance $instance; results => ", > join( '', @results ); > > close PARENT_WRITER; > > exit; > } # if > } # for > > for my $instance ( 1..$numprocs ) { > my $index = $instance - 1; > print $output[ $index ], "\n"; > } # if > > > > -------------------------------------------------------------------------------- > > i execute this as: > > $ date; perl junk; date > > > and get: > > Sat Mar 15 02:30:22 UTC 2008 > 2008-03-15 02:30:27 +0000 child pid 5469; instance 1; results => > hostname_1 > 2008-03-15 02:30:32 +0000 child pid 5471; instance 2; results => > hostname_2 > Sat Mar 15 02:30:32 UTC 2008 > > > it's running the second child process only after the first one > finishes, which defeats my goal of parallelizing. what am i missing? > > there's so much stuff out there that promises to help with this and i > don't know whether i'm going down the wrong path. surely you fine > folks must have done stuff like this before. do indeed tell me to > rtfm, but please tell me which fm (or other doc) to r. > > please also feel free to tell me i'm going about it totally the wrong > way, perhaps with a pointer in the general (better) direction. > > thanks, > david > -- > Live in a world of your own, but always welcome visitors. > _______________________________________________ > SanFrancisco-pm mailing list > SanFrancisco-pm at pm.org > http://mail.pm.org/mailman/listinfo/sanfrancisco-pm --------------------------------------------------------------------- Michael Friedman HighWire Press Phone: 650-725-1974 Stanford University FAX: 270-721-8034 --------------------------------------------------------------------- From biztos at mac.com Fri Mar 14 23:39:23 2008 From: biztos at mac.com (Kevin Frost) Date: Fri, 14 Mar 2008 23:39:23 -0700 Subject: [sf-perl] parallelize system tasks, collecting statuses and output In-Reply-To: <0D87E766-1BEC-4A0A-A6FD-2C2F43E7B674@highwire.stanford.edu> References: <4c714a9c0803141938o327847d7gc7419856c45a1514@mail.gmail.com> <0D87E766-1BEC-4A0A-A6FD-2C2F43E7B674@highwire.stanford.edu> Message-ID: <458154C4-C25B-449E-B06B-2E445EB58E59@mac.com> This sounds like a fun project, but I'm pretty sure there are industry- standard tools that already solve this problem. I don't know what they use, but our guys do this all the time on hundreds of boxes. Just FYI. I'd still do it in perl. :-) -- frosty (via iPhone) On Mar 14, 2008, at 10:12 PM, Michael Friedman wrote: > David, > > I think the sequentialism is in your code. You fork() in a loop, and > each child does its thing, but the parent process -- the one that is > about to fork the next child -- is sitting there waiting on the > child's output: > > chomp( my $line = ); > > Until the child gives it something, you've got blocking IO there. It > won't start the next child until after it's received the output from > the previous child. To make it actually parallel, you have to not wait > on output from the child until after you've created all the children. > You can do that via a double-fork server, some sort of signaling, > or... > > Have you considered using threads? Perl now comes with real live > working thread support (if you compiled it in). The threads API is > pretty brilliant, IMO, as it makes it almost as easy as in Java to > write multi-threaded code. > > http://search.cpan.org/~jdhedden/threads-1.69/threads.pm > > If you didn't happen to compile in thread support, or are running on > someone else's copy of perl who didn't, there's a CPAN module that > emulates the thread API using fork(). It's much slower than real > threads, but lets you write code that works without threads now and > with them later when you can update perl. > > http://search.cpan.org/~rybskej/forks-0.27/lib/forks.pm > > In either case, it explicitly lets you detach from threads and let > them run at their own pace, gathering the results later. Your driving > script can only pick up the results in single file, but threads may > finish in a different order than you started them. I've used this a > couple of times and it's pretty cool. ;-) > > I think the threads API would be a good solution to your problem, if > it's available to you. > > -- Mike > > > On Mar 14, 2008, at 7:38 PM, David Alban wrote: > >> greetings, >> >> our sysadmins regularly need to restart a service on, say thirty >> machines. the service takes two and a half minutes to restart. i'd >> like to write a perl program they can use to parallelize the restart. >> so that the whole operation takes three minutes rather than an hour >> or >> more. i want to collect the statuses and any output of the service >> restart commands. >> >> i found the Bidirectional Communication with Yourself section of the >> perlipc man page. i'm trying to hack their example so that only the >> child writer writes to the parent reader. my hacked version forks >> two >> child processes, which i want to run in parallel. each child process >> ssh's to a host, sleeps a small amount of time, and then runs the >> hostname command. but the child procs seem to be running serially. >> >> #!/usr/bin/perl >> >> use warnings; >> use strict; >> >> # log_timestamp() below comes from this module >> use ; >> >> use IO::Handle; >> >> my @hosts = qw( hostname_1 hostname_2 ); >> my $numprocs = @hosts; >> >> my @output; >> >> for my $instance ( 1..$numprocs ) { >> my $index = $instance - 1; >> >> pipe( CHILD_READER, PARENT_WRITER ) >> or die "can't pipe( CHILD_READER, PARENT_WRITER ): $!\n"; >> >> PARENT_WRITER->autoflush( 1 ); >> >> my $pid; >> >> # parent >> if ( $pid = fork() ) { >> close PARENT_WRITER; >> >> chomp( my $line = ); >> $output[ $index ] = $line; >> >> close CHILD_READER; >> } # if >> >> # child >> else { >> not defined $pid and die "can't fork: $!\n"; >> >> close CHILD_READER; >> >> my $host = $hosts[ $index ]; >> my @results = qx{ ssh $host "sleep 5; hostname" }; >> >> print PARENT_WRITER >> log_timestamp(), >> " child pid $$; instance $instance; results => ", >> join( '', @results ); >> >> close PARENT_WRITER; >> >> exit; >> } # if >> } # for >> >> for my $instance ( 1..$numprocs ) { >> my $index = $instance - 1; >> print $output[ $index ], "\n"; >> } # if >> >> >> >> --- >> --- >> --- >> --- >> -------------------------------------------------------------------- >> >> i execute this as: >> >> $ date; perl junk; date >> >> >> and get: >> >> Sat Mar 15 02:30:22 UTC 2008 >> 2008-03-15 02:30:27 +0000 child pid 5469; instance 1; results => >> hostname_1 >> 2008-03-15 02:30:32 +0000 child pid 5471; instance 2; results => >> hostname_2 >> Sat Mar 15 02:30:32 UTC 2008 >> >> >> it's running the second child process only after the first one >> finishes, which defeats my goal of parallelizing. what am i missing? >> >> there's so much stuff out there that promises to help with this and i >> don't know whether i'm going down the wrong path. surely you fine >> folks must have done stuff like this before. do indeed tell me to >> rtfm, but please tell me which fm (or other doc) to r. >> >> please also feel free to tell me i'm going about it totally the wrong >> way, perhaps with a pointer in the general (better) direction. >> >> thanks, >> david >> -- >> Live in a world of your own, but always welcome visitors. >> _______________________________________________ >> SanFrancisco-pm mailing list >> SanFrancisco-pm at pm.org >> http://mail.pm.org/mailman/listinfo/sanfrancisco-pm > > --------------------------------------------------------------------- > Michael Friedman HighWire Press > Phone: 650-725-1974 Stanford University > FAX: 270-721-8034 > --------------------------------------------------------------------- > > > _______________________________________________ > SanFrancisco-pm mailing list > SanFrancisco-pm at pm.org > http://mail.pm.org/mailman/listinfo/sanfrancisco-pm From merlyn at stonehenge.com Sat Mar 15 08:16:08 2008 From: merlyn at stonehenge.com (Randal L. Schwartz) Date: Sat, 15 Mar 2008 08:16:08 -0700 Subject: [sf-perl] parallelize system tasks, collecting statuses and output In-Reply-To: <4c714a9c0803141938o327847d7gc7419856c45a1514@mail.gmail.com> (David Alban's message of "Fri, 14 Mar 2008 19:38:47 -0700") References: <4c714a9c0803141938o327847d7gc7419856c45a1514@mail.gmail.com> Message-ID: <86d4pwyq4n.fsf@blue.stonehenge.com> >>>>> "David" == David Alban writes: David> our sysadmins regularly need to restart a service on, say thirty David> machines. the service takes two and a half minutes to restart. i'd David> like to write a perl program they can use to parallelize the restart. David> so that the whole operation takes three minutes rather than an hour or David> more. i want to collect the statuses and any output of the service David> restart commands. David> i found the Bidirectional Communication with Yourself section of the David> perlipc man page. i'm trying to hack their example so that only the David> child writer writes to the parent reader. my hacked version forks two David> child processes, which i want to run in parallel. each child process David> ssh's to a host, sleeps a small amount of time, and then runs the David> hostname command. but the child procs seem to be running serially. "Getting your kids to do the work" http://www.stonehenge.com/merlyn/LinuxMag/col15.html Or, just look at Parallel::ForkManager in the CPAN. -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 Perl/Unix/security consulting, Technical writing, Comedy, etc. etc. See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training! From lavendula6654 at yahoo.com Mon Mar 17 18:50:46 2008 From: lavendula6654 at yahoo.com (Elaine) Date: Mon, 17 Mar 2008 18:50:46 -0700 (PDT) Subject: [sf-perl] Software Development Courses at Foothill College Message-ID: <14913.45835.qm@web31708.mail.mud.yahoo.com> Spring quarter classes start Monday, 7 April, at Foothill College. These two may be of interest to you: 1) Application Software Development with Ajax - 5 units Prerequisite: Knowledge of HTML and JavaScript COIN 71 - Tuesday evenings at Middlefield campus in Palo Alto 2) Introduction to Python Programming - 5 units Prerequisite: Any programming language experience CIS 68K - Monday evenings at Middlefield campus in Palo Alto If you are interested in taking a class, please register as soon as possible by going to: http://www.foothill.fhda.edu/reg/index.php If not enough students sign up, a class may be cancelled. If you have any questions, please contact the instructor, Elaine Haight, at haightElaine at foothill.edu ____________________________________________________________________________________ Looking for last minute shopping deals? Find them fast with Yahoo! Search. http://tools.search.yahoo.com/newsearch/category.php?category=shopping From x.sfpug at chatterjee.net Mon Mar 17 23:28:54 2008 From: x.sfpug at chatterjee.net (Anirvan Chatterjee) Date: Mon, 17 Mar 2008 23:28:54 -0700 Subject: [sf-perl] Advice on how to expose a class-wide preference Message-ID: <20080318062854.GA4496@chatterjee.net> I'm looking for advice on how to expose a user-settable preference that affects the behavior of all objects in a given class. I'm working on a module representing data stringifiable in multiple ways, e.g.: $data->normalized $data->full $data->compact I'd like to set up string operator overloading, but it's not obvious what the default stringification style should be; different users will have different needs. I'd like to allow users to choose how objects will stringify by default in their code. I can imagine doing this in two different ways: 1) Have a class-wide preference indicating the default style: Class->default_string_style('normalized'); 2) Let users set their preference via a magic variable: local $Class::default_string_style = 'normalized'; The first option seems cleaner, and easier to subclass (were that an issue); it also allows for better error handling when the user calls the class method. Unfortunately, setting a class-wide flag also blows away any prior settings. Two pieces of code using the module will necessarily overwrite each other's preferences. Using a variable seems uglier, but allows users to safely intermix different preference values in different contexts. Any suggestions on which of these is generally better to use? Are there other strategies I'm ignoring? Thanks for any advice. -- Anirvan Chatterjee www.chatterjee.net www.bookfinder.com From shlomif at iglu.org.il Tue Mar 18 01:50:12 2008 From: shlomif at iglu.org.il (Shlomi Fish) Date: Tue, 18 Mar 2008 10:50:12 +0200 Subject: [sf-perl] Advice on how to expose a class-wide preference In-Reply-To: <20080318062854.GA4496@chatterjee.net> References: <20080318062854.GA4496@chatterjee.net> Message-ID: <200803181050.12869.shlomif@iglu.org.il> Hi Anirvan! On Tuesday 18 March 2008, Anirvan Chatterjee wrote: > I'm looking for advice on how to expose a user-settable preference > that affects the behavior of all objects in a given class. I'm working > on a module representing data stringifiable in multiple ways, e.g.: > > $data->normalized > $data->full > $data->compact > > I'd like to set up string operator overloading, but it's not obvious > what the default stringification style should be; different users will > have different needs. I'd like to allow users to choose how objects > will stringify by default in their code. I can imagine doing this in > two different ways: > > 1) Have a class-wide preference indicating the default style: > > Class->default_string_style('normalized'); > > 2) Let users set their preference via a magic variable: > > local $Class::default_string_style = 'normalized'; > > The first option seems cleaner, and easier to subclass (were that an > issue); it also allows for better error handling when the user calls > the class method. Unfortunately, setting a class-wide flag also blows > away any prior settings. Two pieces of code using the module will > necessarily overwrite each other's preferences. > > Using a variable seems uglier, but allows users to safely intermix > different preference values in different contexts. > > Any suggestions on which of these is generally better to use? Are > there other strategies I'm ignoring? Thanks for any advice. Another option I can think of is to make use of closures to define a certain scope: <<<<<<<<<<<<<<<<<<< $data->as_normalized(sub { # Here $data will stringify as normalized: print "$date"; }); # And here $data will revert back to its previous setting. >>>>>>>>>>>>>>>>>>> And naturally inside the closure you can safely set the setting to any other value, because it will be reverted at the end. Regards, Shlomi Fish --------------------------------------------------------------------- Shlomi Fish shlomif at iglu.org.il Homepage: http://www.shlomifish.org/ I'm not an actor - I just play one on T.V. From moseley at hank.org Tue Mar 18 04:44:43 2008 From: moseley at hank.org (Bill Moseley) Date: Tue, 18 Mar 2008 04:44:43 -0700 Subject: [sf-perl] Advice on how to expose a class-wide preference In-Reply-To: <20080318062854.GA4496@chatterjee.net> References: <20080318062854.GA4496@chatterjee.net> Message-ID: <20080318114442.GD6464@hank.org> On Mon, Mar 17, 2008 at 11:28:54PM -0700, Anirvan Chatterjee wrote: > I'm looking for advice on how to expose a user-settable preference > that affects the behavior of all objects in a given class. I'm working > on a module representing data stringifiable in multiple ways, e.g.: Are the objects created in many different places? That is, would it be that difficult to just specify the type of stringification in the object? my $data = Thing->new( stringification_method => $config->stringification_method, ); If you go the class data route I'd still copy the preference into the object if you might ever want to change the behavior of some objects. -- Bill Moseley moseley at hank.org From woof at danlo.com Tue Mar 18 06:23:23 2008 From: woof at danlo.com (Daniel Lo) Date: Tue, 18 Mar 2008 06:23:23 -0700 Subject: [sf-perl] Advice on how to expose a class-wide preference In-Reply-To: <20080318062854.GA4496@chatterjee.net> References: <20080318062854.GA4496@chatterjee.net> Message-ID: <199058546.20080318062323@danlo.com> Hello Anirvan, It appears to me that you are talking about a User Interface description. I don't know of any reason for a class API to return different results depending on a normalized, full, or compact method. (At least I can't think of one right now. :) Your code should never very in its return values other wise you will be writing different APIs for each object/function to handle receiving $data->normalized() $data->full() $data->compact() and $data->human() $data->and_so_on. Things get exponentially worse after that. If you are debating on how to return content for the end user, you should always return $data->full(). Then the templating code or the display code should be responsible for taking $data->full() and making it normalized, compact or full. You should consider a visitor pattern or using Template::Toolkit (very good btw). http://en.wikipedia.org/wiki/Visitor_pattern. This is great for deciding how you want to display the data. You may want to check out Class::Prototyped ( very cool :) http://search.cpan.org/~teverett/Class-Prototyped-1.11/lib/Class/Prototyped.pm -daniel Monday, March 17, 2008, 11:28:54 PM, you wrote: > I'm looking for advice on how to expose a user-settable preference > that affects the behavior of all objects in a given class. I'm working > on a module representing data stringifiable in multiple ways, e.g.: > $data->normalized > $data->full > $data->compact > I'd like to set up string operator overloading, but it's not obvious > what the default stringification style should be; different users will > have different needs. I'd like to allow users to choose how objects > will stringify by default in their code. I can imagine doing this in > two different ways: > 1) Have a class-wide preference indicating the default style: > Class->default_string_style('normalized'); > 2) Let users set their preference via a magic variable: > local $Class::default_string_style = 'normalized'; > The first option seems cleaner, and easier to subclass (were that an > issue); it also allows for better error handling when the user calls > the class method. Unfortunately, setting a class-wide flag also blows > away any prior settings. Two pieces of code using the module will > necessarily overwrite each other's preferences. > Using a variable seems uglier, but allows users to safely intermix > different preference values in different contexts. > Any suggestions on which of these is generally better to use? Are > there other strategies I'm ignoring? Thanks for any advice. -- Best regards, Daniel mailto:woof at danlo.com From sphink at gmail.com Tue Mar 18 13:12:46 2008 From: sphink at gmail.com (Steve Fink) Date: Tue, 18 Mar 2008 13:12:46 -0700 Subject: [sf-perl] Advice on how to expose a class-wide preference In-Reply-To: <20080318062854.GA4496@chatterjee.net> References: <20080318062854.GA4496@chatterjee.net> Message-ID: <7d7f2e8c0803181312l79bc3d80lea00f6daecf3e683@mail.gmail.com> On Mon, Mar 17, 2008 at 11:28 PM, Anirvan Chatterjee wrote: > 1) Have a class-wide preference indicating the default style: > > Class->default_string_style('normalized'); > > 2) Let users set their preference via a magic variable: > > local $Class::default_string_style = 'normalized'; > > The first option seems cleaner, and easier to subclass (were that an > issue); it also allows for better error handling when the user calls > the class method. Unfortunately, setting a class-wide flag also blows > away any prior settings. Two pieces of code using the module will > necessarily overwrite each other's preferences. > > Using a variable seems uglier, but allows users to safely intermix > different preference values in different contexts. Just to add to the set of possibilities, you could make the settings only apply to the package that requested them. So the syntax could either be your original #1: Class->default_string_style('normalized') or you could make it explicit Class->default_string_style(__PACKAGE__, 'normalized') default_string_style() would then use caller() or the passed-in package name to record who wants what, and the stringification would use caller() to decide whose setting to use. I'm not recommending it, just pointing it out. If you really wanted to be able to use local() but still have package-scoping, you could always do our $STRINGIFICATION_SETTING; local $STRINGIFICATION_SETTING = ...; and have stringification use caller() to look up that variable in its caller's package. Whee. From fluxnet at gmail.com Tue Mar 18 14:37:07 2008 From: fluxnet at gmail.com (Bern) Date: Tue, 18 Mar 2008 14:37:07 -0700 Subject: [sf-perl] Advice on how to expose a class-wide preference In-Reply-To: <7d7f2e8c0803181312l79bc3d80lea00f6daecf3e683@mail.gmail.com> References: <20080318062854.GA4496@chatterjee.net> <7d7f2e8c0803181312l79bc3d80lea00f6daecf3e683@mail.gmail.com> Message-ID: hi, sorry need to ask when is the next meeting ? or any other meetings and or events in the sfbay area, thanks On Tue, Mar 18, 2008 at 1:12 PM, Steve Fink wrote: > On Mon, Mar 17, 2008 at 11:28 PM, Anirvan Chatterjee > wrote: > > 1) Have a class-wide preference indicating the default style: > > > > Class->default_string_style('normalized'); > > > > 2) Let users set their preference via a magic variable: > > > > local $Class::default_string_style = 'normalized'; > > > > The first option seems cleaner, and easier to subclass (were that an > > issue); it also allows for better error handling when the user calls > > the class method. Unfortunately, setting a class-wide flag also blows > > away any prior settings. Two pieces of code using the module will > > necessarily overwrite each other's preferences. > > > > Using a variable seems uglier, but allows users to safely intermix > > different preference values in different contexts. > > Just to add to the set of possibilities, you could make the settings > only apply to the package that requested them. So the syntax could > either be your original #1: > > Class->default_string_style('normalized') > > or you could make it explicit > > Class->default_string_style(__PACKAGE__, 'normalized') > > default_string_style() would then use caller() or the passed-in > package name to record who wants what, and the stringification would > use caller() to decide whose setting to use. > > I'm not recommending it, just pointing it out. > > If you really wanted to be able to use local() but still have > package-scoping, you could always do > > our $STRINGIFICATION_SETTING; > local $STRINGIFICATION_SETTING = ...; > > and have stringification use caller() to look up that variable in its > caller's package. > > Whee. > _______________________________________________ > SanFrancisco-pm mailing list > SanFrancisco-pm at pm.org > http://mail.pm.org/mailman/listinfo/sanfrancisco-pm > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.pm.org/pipermail/sanfrancisco-pm/attachments/20080318/48ce9eff/attachment.html From quinn at fairpath.com Tue Mar 18 16:38:51 2008 From: quinn at fairpath.com (Quinn Weaver) Date: Tue, 18 Mar 2008 15:38:51 -0800 Subject: [sf-perl] Advice on how to expose a class-wide preference In-Reply-To: References: <20080318062854.GA4496@chatterjee.net> <7d7f2e8c0803181312l79bc3d80lea00f6daecf3e683@mail.gmail.com> Message-ID: <20080318233851.GA75876@fu.funkspiel.org> On Tue, Mar 18, 2008 at 02:37:07PM -0700, Bern wrote: > hi, sorry need to ask when is the next meeting ? or any other meetings and > or events in the sfbay area, thanks My bad--I haven't marked this up to the Web site yet. Our next meeting is March 25. We will join BALUG in a dinner with Mark Shuttleworth, the founder of Canonical--the company behind Ubuntu. (Mark is also famous as the founder of Thawte and as a space tourist.) Andrew Fife of BALUG has kindly agreed to set aside a table for SF.pm. If you will be attending, please mail me. I need to get Andrew an accurate RSVP count. For more details, see http://www.balug.org/ (scroll down to "Next meetings:"). I will post this on sf.pm.org soon. Thanks! -- Quinn Weaver, independent contractor | President, San Francisco Perl Mongers http://fairpath.com/quinn/resume/ | http://sf.pm.org/ 510-520-5217 From fluxnet at gmail.com Tue Mar 18 20:31:14 2008 From: fluxnet at gmail.com (Bern) Date: Tue, 18 Mar 2008 20:31:14 -0700 Subject: [sf-perl] Advice on how to expose a class-wide preference In-Reply-To: <20080318233851.GA75876@fu.funkspiel.org> References: <20080318062854.GA4496@chatterjee.net> <7d7f2e8c0803181312l79bc3d80lea00f6daecf3e683@mail.gmail.com> <20080318233851.GA75876@fu.funkspiel.org> Message-ID: mail u here to sanfrancisco-pm at pm.org or ? please consider me a sure thing On Tue, Mar 18, 2008 at 4:38 PM, Quinn Weaver wrote: > On Tue, Mar 18, 2008 at 02:37:07PM -0700, Bern wrote: > > hi, sorry need to ask when is the next meeting ? or any other meetings > and > > or events in the sfbay area, thanks > > My bad--I haven't marked this up to the Web site yet. > > Our next meeting is March 25. We will join BALUG in a dinner with > Mark Shuttleworth, the founder of Canonical--the company behind Ubuntu. > (Mark is also famous as the founder of Thawte and as a space tourist.) > > Andrew Fife of BALUG has kindly agreed to set aside a table for SF.pm. > If you will be attending, please mail me. I need to get Andrew > an accurate RSVP count. > > For more details, see http://www.balug.org/ (scroll down to "Next > meetings:"). > I will post this on sf.pm.org soon. > > Thanks! > > -- > Quinn Weaver, independent contractor | President, San Francisco Perl > Mongers > http://fairpath.com/quinn/resume/ | http://sf.pm.org/ > 510-520-5217 > _______________________________________________ > SanFrancisco-pm mailing list > SanFrancisco-pm at pm.org > http://mail.pm.org/mailman/listinfo/sanfrancisco-pm > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.pm.org/pipermail/sanfrancisco-pm/attachments/20080318/481375dc/attachment.html From pm.org at daveola.com Wed Mar 19 17:07:45 2008 From: pm.org at daveola.com (David Ljung Madison) Date: Wed, 19 Mar 2008 17:07:45 -0700 Subject: [sf-perl] Porting to Windows and writing a GUI? (ugh) Message-ID: I have a shareware script that I've mostly ported to Windows via CygWin (and ActivePerl, at one point). I wanted to write/get a GUI front-end to call the script (and maybe an installer as well) so I can make it a little more user-friendly for the non-perl users out there. I don't really do Windows myself, so I might just hire someone to make the front-end (whether in perl or not), but it occurred to me that someone may have already solved this problem in the general sense. It would be snifty, it seems to me, if there was a GUI that could call a script and could be customized for some of the command-line flags, or, even better, could perhaps read them from the script itself. Any suggestions? And if not - any thoughts on where I could hire someone for a small job like this? Dave Root --------------------------------------------------------------------------- Dave Ljung Madison http://GetDave.com/ 415.341.5555 --- I am totally into Perl now. I love it. It rules with an iron fist. -- From doom at kzsu.stanford.edu Wed Mar 19 18:54:18 2008 From: doom at kzsu.stanford.edu (Joe Brenner) Date: Wed, 19 Mar 2008 18:54:18 -0700 Subject: [sf-perl] Porting to Windows and writing a GUI? (ugh) In-Reply-To: References: Message-ID: <200803200154.m2K1sIfc060398@kzsu.stanford.edu> David Ljung Madison wrote: > I have a shareware script that I've mostly ported to Windows > via CygWin (and ActivePerl, at one point). > > I wanted to write/get a GUI front-end to call the script > (and maybe an installer as well) so I can make it a little > more user-friendly for the non-perl users out there. There are a few existing toolkits that could be used to do something like this. Tk is the traditional one, but lately people have been talking about Wx, which I believe is supposed to look a little better (or more like a native app): http://search.cpan.org/dist/Wx/ If you try this, don't forget to check the Install file: "You need to install wxWidgets before you can compile wxPerl." From ddascalescu at gmail.com Thu Mar 20 20:12:31 2008 From: ddascalescu at gmail.com (Dan Dascalescu) Date: Thu, 20 Mar 2008 20:12:31 -0700 Subject: [sf-perl] Porting to Windows and writing a GUI? (ugh) In-Reply-To: <200803200154.m2K1sIfc060398@kzsu.stanford.edu> References: <200803200154.m2K1sIfc060398@kzsu.stanford.edu> Message-ID: <3561cc6d0803202012x635ba8c8r25a32ab332b24a5@mail.gmail.com> I've found Win32::GUI much easier to comprehend, use and get started with. Dan On Wed, Mar 19, 2008 at 6:54 PM, Joe Brenner wrote: > > David Ljung Madison wrote: > > > I have a shareware script that I've mostly ported to Windows > > via CygWin (and ActivePerl, at one point). > > > > I wanted to write/get a GUI front-end to call the script > > (and maybe an installer as well) so I can make it a little > > more user-friendly for the non-perl users out there. > > There are a few existing toolkits that could be used to do something > like this. Tk is the traditional one, but lately people have been > talking about Wx, which I believe is supposed to look a little better > (or more like a native app): > > http://search.cpan.org/dist/Wx/ > > If you try this, don't forget to check the Install file: > > "You need to install wxWidgets before you can compile wxPerl." From quinn at fairpath.com Mon Mar 24 09:21:16 2008 From: quinn at fairpath.com (Quinn Weaver) Date: Mon, 24 Mar 2008 08:21:16 -0800 Subject: [sf-perl] Reminder: Mark Shuttleworth tomorrow. RSVP! Message-ID: <20080324162116.GA10796@fu.funkspiel.org> Reminder: Mark Shuttleworth is speaking at BALUG tomorrow night. BALUG has offered to give us a special table, but we need an RSVP count. So far I've received only one. If you want to join us, please mail me at quinn at fairpath.com (don't reply to the list) and I'll get you on the guest list. If you don't want to sit with us, you don't have to RSVP, but it does help the BALUG folks. Thanks a lot, -- Quinn Weaver, independent contractor | President, San Francisco Perl Mongers http://fairpath.com/quinn/resume/ | http://sf.pm.org/ 510-520-5217 From rdm at cfcl.com Tue Mar 25 08:53:51 2008 From: rdm at cfcl.com (Rich Morin) Date: Tue, 25 Mar 2008 07:53:51 -0800 Subject: [sf-perl] Freeway Threeway - three evening of goodness! Message-ID: Even if you've been hiding under the covers, waiting for things to quiet down a bit, you're probably aware of the week's events: Tue: BALUG (San Francisco) - Mark Shuttleworth on Ubuntu, etc. -- http://www.new.balug.org Wed: BASS (San Francisco) - the usual Beer, Pizza, and chatter -- http://www.cfcl.com/rdm/bass Thu: PC&P (Redwood City) - pizza and a double feature on RSpec -- http://ruby.meetup.com/123/calendar/7190591/ Be there or be elsewhere... -r -- http://www.cfcl.com/rdm Rich Morin http://www.cfcl.com/rdm/resume rdm at cfcl.com http://www.cfcl.com/rdm/weblog +1 650-873-7841 Technical editing and writing, programming, and web development From quinn at fairpath.com Tue Mar 25 18:09:16 2008 From: quinn at fairpath.com (Quinn Weaver) Date: Tue, 25 Mar 2008 17:09:16 -0800 Subject: [sf-perl] Reminder: Mark Shuttleworth tomorrow. RSVP! In-Reply-To: <20080324162116.GA10796@fu.funkspiel.org> References: <20080324162116.GA10796@fu.funkspiel.org> Message-ID: <20080326010916.GB38456@fu.funkspiel.org> BALUG update: Thanks for the RSVPs. We have seven people confirmed. There should be a table with a sign just for us. Unfortunately, and to my immense regret, I won't be there. I realized at the last minute that I double-booked tonight. Double duh. The other event can't happen without me, so I have to drop BALUG. Needless to say, I am really bummed. I would be enormously grateful if someone could ask Mark this question, in some form (write it down or paraphrase, I don't care which): What would it take for Kubuntu or Ubuntu to become as popular as, or more popular than, Windows and Macs on the desktop? I know the answer of many people on this list would be "It'll never happen" or "The Mac OS X GUI is way better." But I want Mark's opinion. :) Thanks, and see you next time, -- Quinn Weaver, independent contractor | President, San Francisco Perl Mongers http://fairpath.com/quinn/resume/ | http://sf.pm.org/ 510-520-5217 From quinn at fairpath.com Fri Mar 28 12:10:35 2008 From: quinn at fairpath.com (Quinn Weaver) Date: Fri, 28 Mar 2008 11:10:35 -0800 Subject: [sf-perl] LugRadio is on Message-ID: <20080328191035.GA71716@fu.funkspiel.org> And now for some pleasant news. We've reached our staffing goals, and LugRadio has confirmed us for a booth. We're on! So far we have Joe, Fred, Yary, and me covering shifts. I'm going to start an off-list thread to handle logistics. If you want to, it's not too late to pitch in; email me (now or later) and I'll add you to that thread. For the record, here are the tasks that need doing: - Next two weeks: print a sign. I'll take point on this. - Next two weeks: help us set up an awesome Perl demo app. Brian's Google mashup would be good, if he wants to bring it again. Ideally, I'd also like to have something that doesn't depend on the wifi network (conferences' shared wifi is notoriously flaky). - Friday evening, April 10: load-in and booth setup (sign, books, computer[s]). - Saturday: booth staffing - Sunday: booth staffing - Sunday afternoon: teardown That's it! Hope to see you at the conference, and/or on the other thread. :) Thanks, -- Quinn Weaver, independent contractor | President, San Francisco Perl Mongers http://fairpath.com/quinn/resume/ | http://sf.pm.org/ 510-520-5217 From nheller at silcon.com Fri Mar 28 12:44:28 2008 From: nheller at silcon.com (Neil Heller) Date: Fri, 28 Mar 2008 12:44:28 -0700 Subject: [sf-perl] Sorting vs. hash In-Reply-To: <20080328191035.GA71716@fu.funkspiel.org> References: <20080328191035.GA71716@fu.funkspiel.org> Message-ID: <005001c8910c$22f2c630$68d85290$@com> An interesting question came up. Suppose you have a large number (> 250k) of strings in an array. You wish to eliminate duplicates. Is it faster to sort the array and then iterate once through the list (writing selected ones to a new array) or write them all into a hash (at which time duplicates would be naturally eliminated)? Neil Heller From fluxnet at gmail.com Fri Mar 28 12:49:43 2008 From: fluxnet at gmail.com (Bern) Date: Fri, 28 Mar 2008 12:49:43 -0700 Subject: [sf-perl] Sorting vs. hash In-Reply-To: <005001c8910c$22f2c630$68d85290$@com> References: <20080328191035.GA71716@fu.funkspiel.org> <005001c8910c$22f2c630$68d85290$@com> Message-ID: hash will never be faster then nothing (at least me thinks) you can benchmark them tho On Fri, Mar 28, 2008 at 12:44 PM, Neil Heller wrote: > > An interesting question came up. > > Suppose you have a large number (> 250k) of strings in an array. > You wish to eliminate duplicates. > > Is it faster to sort the array and then iterate once through the list > (writing selected ones to a new array) or write them all into a hash (at > which time duplicates would be naturally eliminated)? > > Neil Heller > > > _______________________________________________ > SanFrancisco-pm mailing list > SanFrancisco-pm at pm.org > http://mail.pm.org/mailman/listinfo/sanfrancisco-pm > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.pm.org/pipermail/sanfrancisco-pm/attachments/20080328/26460eee/attachment.html From andy at petdance.com Fri Mar 28 12:52:16 2008 From: andy at petdance.com (Andy Lester) Date: Fri, 28 Mar 2008 14:52:16 -0500 Subject: [sf-perl] Sorting vs. hash In-Reply-To: <005001c8910c$22f2c630$68d85290$@com> References: <20080328191035.GA71716@fu.funkspiel.org> <005001c8910c$22f2c630$68d85290$@com> Message-ID: <4B3D7CEC-A9C9-4025-AF31-5309929AB06D@petdance.com> On Mar 28, 2008, at 2:44 PM, Neil Heller wrote: > Is it faster to sort the array and then iterate once through the list > (writing selected ones to a new array) or write them all into a hash > (at > which time duplicates would be naturally eliminated)? It's easy enough to test it and not have to speculate idly. -- Andy Lester => andy at petdance.com => www.petdance.com => AIM:petdance From nheller at silcon.com Fri Mar 28 13:15:44 2008 From: nheller at silcon.com (Neil Heller) Date: Fri, 28 Mar 2008 13:15:44 -0700 Subject: [sf-perl] Sorting vs. hash In-Reply-To: <4B3D7CEC-A9C9-4025-AF31-5309929AB06D@petdance.com> References: <20080328191035.GA71716@fu.funkspiel.org> <005001c8910c$22f2c630$68d85290$@com> <4B3D7CEC-A9C9-4025-AF31-5309929AB06D@petdance.com> Message-ID: <006b01c89110$8110df50$83329df0$@com> It's easy to fill an array with 250,0000 or more strings? Neil Heller 510-862-4387 -----Original Message----- From: sanfrancisco-pm-bounces+nheller=silcon.com at pm.org [mailto:sanfrancisco-pm-bounces+nheller=silcon.com at pm.org] On Behalf Of Andy Lester Sent: Friday, March 28, 2008 12:52 PM To: San Francisco Perl Mongers User Group Subject: Re: [sf-perl] Sorting vs. hash On Mar 28, 2008, at 2:44 PM, Neil Heller wrote: > Is it faster to sort the array and then iterate once through the list > (writing selected ones to a new array) or write them all into a hash > (at > which time duplicates would be naturally eliminated)? It's easy enough to test it and not have to speculate idly. -- Andy Lester => andy at petdance.com => www.petdance.com => AIM:petdance _______________________________________________ SanFrancisco-pm mailing list SanFrancisco-pm at pm.org http://mail.pm.org/mailman/listinfo/sanfrancisco-pm From andy at petdance.com Fri Mar 28 13:18:51 2008 From: andy at petdance.com (Andy Lester) Date: Fri, 28 Mar 2008 15:18:51 -0500 Subject: [sf-perl] Sorting vs. hash In-Reply-To: <006b01c89110$8110df50$83329df0$@com> References: <20080328191035.GA71716@fu.funkspiel.org> <005001c8910c$22f2c630$68d85290$@com> <4B3D7CEC-A9C9-4025-AF31-5309929AB06D@petdance.com> <006b01c89110$8110df50$83329df0$@com> Message-ID: <224D33B1-CD23-469E-A62A-81293A3CD84D@petdance.com> On Mar 28, 2008, at 3:15 PM, Neil Heller wrote: > It's easy to fill an array with 250,0000 or more strings? Sure. -- Andy Lester => andy at petdance.com => www.petdance.com => AIM:petdance From biztos at mac.com Fri Mar 28 13:22:45 2008 From: biztos at mac.com (frosty) Date: Fri, 28 Mar 2008 13:22:45 -0700 Subject: [sf-perl] Sorting vs. hash In-Reply-To: <006b01c89110$8110df50$83329df0$@com> References: <20080328191035.GA71716@fu.funkspiel.org> <005001c8910c$22f2c630$68d85290$@com> <4B3D7CEC-A9C9-4025-AF31-5309929AB06D@petdance.com> <006b01c89110$8110df50$83329df0$@com> Message-ID: <519061F2-0118-1000-9552-CDA1EBCAFC30-Webmail-10019@mac.com> Sure. See below. I think the sorting trick is fastest. use strict; use warnings; use Benchmark; # starting point: one big fat array (Neil says 250K). # but let's assume there are some dupes. my @input; my @ltr = ( 'a' .. 'z' ); my $dupe_count = 0; while ( @input < 250000 ) { my $t = join( '', map { $ltr[ rand(@ltr) ] } ( 1 .. rand(40) + 10 ) ); push( @input, $t ); # Eliminating dupes is the point. if ( @input / 20 == int( @input / 20 ) ) { unshift( @input, $t ); $dupe_count++; } } printf "%d strings (%d dupes)\n", scalar(@input), $dupe_count; timethese( 100, { SortStyle => \&array_strip_without_hash, SeenStyle => \&array_strip_with_hash, SimpleHash => \&hash_strip, SortedHash => \&hash_strip_sort } ); sub array_strip_without_hash { # This strikes me as really dumb, but... my @new_array; my $last_item = ''; foreach my $item ( sort @input ) { next if $item eq $last_item; $last_item = $item; push( @new_array, $item ); } die "oops" unless @new_array == @input - $dupe_count; } sub array_strip_with_hash { # My thinking is this is also dumb. my @new_array; my %seen; foreach my $item (@input) { next if $seen{$item}; push( @new_array, $item ); $seen{$item} = 1; } die "oops" unless @new_array == @input - $dupe_count; } sub hash_strip { my %new_hash = map { $_ => 1 } @input; my @new_array = keys %new_hash; die "oops" unless @new_array == @input - $dupe_count; } sub hash_strip_sort { # because it's more useful. my %new_hash = map { $_ => 1 } @input; my @new_array = sort keys %new_hash; die "oops" unless @new_array == @input - $dupe_count; } On Friday, March 28, 2008, at 01:16PM, "Neil Heller" wrote: >It's easy to fill an array with 250,0000 or more strings? > >Neil Heller >510-862-4387 > > >-----Original Message----- >From: sanfrancisco-pm-bounces+nheller=silcon.com at pm.org >[mailto:sanfrancisco-pm-bounces+nheller=silcon.com at pm.org] On Behalf Of Andy >Lester >Sent: Friday, March 28, 2008 12:52 PM >To: San Francisco Perl Mongers User Group >Subject: Re: [sf-perl] Sorting vs. hash > > >On Mar 28, 2008, at 2:44 PM, Neil Heller wrote: >> Is it faster to sort the array and then iterate once through the list >> (writing selected ones to a new array) or write them all into a hash >> (at >> which time duplicates would be naturally eliminated)? > > >It's easy enough to test it and not have to speculate idly. > >-- >Andy Lester => andy at petdance.com => www.petdance.com => AIM:petdance > > > > >_______________________________________________ >SanFrancisco-pm mailing list >SanFrancisco-pm at pm.org >http://mail.pm.org/mailman/listinfo/sanfrancisco-pm > >_______________________________________________ >SanFrancisco-pm mailing list >SanFrancisco-pm at pm.org >http://mail.pm.org/mailman/listinfo/sanfrancisco-pm > > From gregc at cnet.com Fri Mar 28 13:26:39 2008 From: gregc at cnet.com (greg lee coleman [1482]) Date: Fri, 28 Mar 2008 13:26:39 -0700 (PDT) Subject: [sf-perl] Sorting vs. hash In-Reply-To: <519061F2-0118-1000-9552-CDA1EBCAFC30-Webmail-10019@mac.com> References: <20080328191035.GA71716@fu.funkspiel.org> <005001c8910c$22f2c630$68d85290$@com> <4B3D7CEC-A9C9-4025-AF31-5309929AB06D@petdance.com> <006b01c89110$8110df50$83329df0$@com> <519061F2-0118-1000-9552-CDA1EBCAFC30-Webmail-10019@mac.com> Message-ID: i know he's lurking, but anyway - http://en.wikipedia.org/wiki/Schwartzian_transform hth, -gleeco From biztos at mac.com Fri Mar 28 13:28:38 2008 From: biztos at mac.com (frosty) Date: Fri, 28 Mar 2008 13:28:38 -0700 Subject: [sf-perl] Sorting vs. hash In-Reply-To: <519061F2-0118-1000-9552-CDA1EBCAFC30-Webmail-10019@mac.com> References: <20080328191035.GA71716@fu.funkspiel.org> <005001c8910c$22f2c630$68d85290$@com> <4B3D7CEC-A9C9-4025-AF31-5309929AB06D@petdance.com> <006b01c89110$8110df50$83329df0$@com> <519061F2-0118-1000-9552-CDA1EBCAFC30-Webmail-10019@mac.com> Message-ID: <519061F2-0118-1000-9572-CDA1EBCAFC30-Webmail-10019@mac.com> D'oh, no! I take it back! That'll teach me to not wait for my benchmarks to run. It looks like the good old %seen trick is fastest on my MacBook Pro (sysperl, 5.8.8). The hash via map stuff is a lot slower. If I had more time to play with it I'd like to know which parts make it slower but I have to get back to work. My hunch is that if you really cared, you could make the sort thingy the fastest by using a different sort algo. -- f. On Friday, March 28, 2008, at 01:23PM, "frosty" wrote: >Sure. See below. I think the sorting trick is fastest. > >use strict; >use warnings; >use Benchmark; > ># starting point: one big fat array (Neil says 250K). ># but let's assume there are some dupes. >my @input; >my @ltr = ( 'a' .. 'z' ); >my $dupe_count = 0; >while ( @input < 250000 ) { > my $t = join( '', map { $ltr[ rand(@ltr) ] } ( 1 .. rand(40) + 10 ) ); > push( @input, $t ); > > # Eliminating dupes is the point. > if ( @input / 20 == int( @input / 20 ) ) { > unshift( @input, $t ); > $dupe_count++; > } >} >printf "%d strings (%d dupes)\n", scalar(@input), $dupe_count; > >timethese( > 100, > { > > SortStyle => \&array_strip_without_hash, > SeenStyle => \&array_strip_with_hash, > SimpleHash => \&hash_strip, > SortedHash => \&hash_strip_sort > } >); > >sub array_strip_without_hash { > > # This strikes me as really dumb, but... > my @new_array; > my $last_item = ''; > foreach my $item ( sort @input ) { > next if $item eq $last_item; > $last_item = $item; > push( @new_array, $item ); > > } > die "oops" unless @new_array == @input - $dupe_count; > >} > >sub array_strip_with_hash { > > # My thinking is this is also dumb. > my @new_array; > my %seen; > foreach my $item (@input) { > next if $seen{$item}; > push( @new_array, $item ); > $seen{$item} = 1; > } > die "oops" unless @new_array == @input - $dupe_count; > >} > >sub hash_strip { > > my %new_hash = map { $_ => 1 } @input; > my @new_array = keys %new_hash; > die "oops" unless @new_array == @input - $dupe_count; > >} > >sub hash_strip_sort { > > # because it's more useful. > my %new_hash = map { $_ => 1 } @input; > my @new_array = sort keys %new_hash; > die "oops" unless @new_array == @input - $dupe_count; >} > > >On Friday, March 28, 2008, at 01:16PM, "Neil Heller" wrote: >>It's easy to fill an array with 250,0000 or more strings? >> >>Neil Heller >>510-862-4387 >> >> >>-----Original Message----- >>From: sanfrancisco-pm-bounces+nheller=silcon.com at pm.org >>[mailto:sanfrancisco-pm-bounces+nheller=silcon.com at pm.org] On Behalf Of Andy >>Lester >>Sent: Friday, March 28, 2008 12:52 PM >>To: San Francisco Perl Mongers User Group >>Subject: Re: [sf-perl] Sorting vs. hash >> >> >>On Mar 28, 2008, at 2:44 PM, Neil Heller wrote: >>> Is it faster to sort the array and then iterate once through the list >>> (writing selected ones to a new array) or write them all into a hash >>> (at >>> which time duplicates would be naturally eliminated)? >> >> >>It's easy enough to test it and not have to speculate idly. >> >>-- >>Andy Lester => andy at petdance.com => www.petdance.com => AIM:petdance >> >> >> >> >>_______________________________________________ >>SanFrancisco-pm mailing list >>SanFrancisco-pm at pm.org >>http://mail.pm.org/mailman/listinfo/sanfrancisco-pm >> >>_______________________________________________ >>SanFrancisco-pm mailing list >>SanFrancisco-pm at pm.org >>http://mail.pm.org/mailman/listinfo/sanfrancisco-pm >> >> >_______________________________________________ >SanFrancisco-pm mailing list >SanFrancisco-pm at pm.org >http://mail.pm.org/mailman/listinfo/sanfrancisco-pm > >