From rjbs-perl-abe at lists.manxome.org Tue Oct 2 08:44:20 2007 From: rjbs-perl-abe at lists.manxome.org (Ricardo SIGNES) Date: Tue, 2 Oct 2007 11:44:20 -0400 Subject: [ABE.pm] see you tomorrow Message-ID: <20071002154420.GA19045@knight> I'll see you folks tomorrow at McGrady's at 18:00. Apress sent me a heap of catalogs, which I will distribute to you. I think I'll soon be dipping back into their Practical Common Lisp, so that I can be more prepared for doing something fun with http://www.xach.com/lisp/vecto/ -- rjbs From faber at linuxnj.com Tue Oct 2 13:02:32 2007 From: faber at linuxnj.com (Faber J. Fedor) Date: Tue, 2 Oct 2007 16:02:32 -0400 Subject: [ABE.pm] Fw: [lugip] [Fwd: Perl/PHP/Joomla] Message-ID: <20071002200231.GA6803@neptune.faber.nom> ----- Forwarded message from Edward Corrado ----- Date: Tue, 02 Oct 2007 14:04:57 -0400 From: Edward Corrado To: lugip at lugip.org Subject: [lugip] [Fwd: Perl/PHP/Joomla] FYI.... -------- Original Message -------- Hello, I work for Diversified Technical Solutions, Inc. Diversified is a technical recruiting firm based in Northern NJ. I am currently working with my client to fill a Perl/PHP/Joomla Developer position here in NJ. The position is a Full Time opportunity. I have been speaking with lots of Perl developers across the United States and they recommend that I reach out to some user groups in NJ. My client needs someone based in NJ. Would you be able to help me with this. Do you know of any job boards that Perl Programmers frequent often. Or do you know of anyone with this type of background that is looking for a new opportunity. Any help would be greatly appreciated. Thank you. Carolyn Russo Diversified Technical Solutions, Inc. 973-439-0451 x13 Fax: 973-439-0813 carolynr at dtsnj.com _______________________________________________ Lugip mailing list Lugip at lugip.org http://www.lugip.org/mailman/listinfo/lugip -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. ----- End forwarded message ----- -- Regards, Faber Fedor President Linux New Jersey, Inc. 908-320-0357 800-706-0701 http://www.linuxnj.com -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. From faber at linuxnj.com Wed Oct 3 19:12:09 2007 From: faber at linuxnj.com (Faber J. Fedor) Date: Wed, 3 Oct 2007 22:12:09 -0400 Subject: [ABE.pm] robot chicken-star wars darth vader calls Message-ID: <20071004021209.GA12013@neptune.faber.nom> As mentioned at tonight's "meeting": http://uk.youtube.com/watch?v=Fc_6d6byLs8 (Why are all the yuotubes coming from the UK lately?) http://en.wikipedia.org/wiki/Kelly's_Heroes -- Regards, Faber Fedor President Linux New Jersey, Inc. 908-320-0357 800-706-0701 http://www.linuxnj.com -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. From rjbs-perl-abe at lists.manxome.org Thu Oct 4 05:15:55 2007 From: rjbs-perl-abe at lists.manxome.org (Ricardo SIGNES) Date: Thu, 4 Oct 2007 08:15:55 -0400 Subject: [ABE.pm] video mentioned last night Message-ID: <20071004121555.GA6266@knight.cable.rcn.com> http://youtube.com/watch?v=T6xJzAYYrX8 -- rjbs From rjbs-perl-abe at lists.manxome.org Thu Oct 4 16:05:37 2007 From: rjbs-perl-abe at lists.manxome.org (Ricardo SIGNES) Date: Thu, 4 Oct 2007 19:05:37 -0400 Subject: [ABE.pm] pittsburgh perl workshop Message-ID: <20071004230537.GC696@knight.cable.rcn.com> A final-ish reminder: you should go! --- The 2007 Pittsburgh Perl Workshop is only 10 days away. The Pittsburgh Perl Mongers are pleased to announce The PITTSBURGH PERL WORKSHOP, a two-day, low-cost conference on Saturday and Sunday, October 13-14, 2007. The Pittsburgh Perl Workshop is an annual conference dedicated to the Perl programming language. In 2006, the Pittsburgh Perl Mongers hosted the first Perl Workshop based in the United States. This year, the Workshop has been expanded to two days. The 2007 Workshop is structured as a series of short lectures, but the atmosphere is low key and engaging: the perfect combination to open your mind and then cram it full of good stuff. After last year's conference you gave us lots of feedback, and we listened. * The workshop was expanded to a two-day event to allow for more talks, birds-of-a-feather sessions, and social interactions. * A one-day course for programmers with little or no Perl experience?-taught by a world-class Perl trainer?-was added. * The schedule has been improved to allow you more flexibility in choosing sessions to attend. Lightning Talks There?s still time to get a third of your fifteen minutes of fame! Submit your lightning talk today. The deadline for early acceptance is one week before the conference (October 6). But if you have an idea on the first day of the conference, we?re holding at least two lightning talk spots until the end of that day. However, you have a much better chance of being accepted if submit your talk now. Stay up to date with everything that's going on with the Perl Workshop by subscribing to our RSS feed at http://pghpw.org/ppw2007/atom/en.xml. If you are coming to the Friday Social, RSVP at http://pghpw.org/ppw2007/wiki?node=Friday%20Social. Full details are on the Workshop Web site at http://pghpw.org. Hope to see you there. Robert Blackwell ----- End forwarded message ----- -- rjbs From faber at linuxnj.com Thu Oct 4 17:03:56 2007 From: faber at linuxnj.com (Faber J. Fedor) Date: Thu, 4 Oct 2007 20:03:56 -0400 Subject: [ABE.pm] trapping warnings Message-ID: <20071005000356.GA16111@neptune.faber.nom> I've got some code like this: $sum = $indexTable2->elm($i, "weight"); while ($sum <= $captPercentile) { $sum += $indexTable2->elm($i+1, "weight"); $bottom_count ++; $i++; } If indexTable2 is empty (it should never be, but hey this is RL), I get errors like: Row index out of range [0..-1]Use of uninitialized value in addition (+) at /home/sqa/bin/processMonthlyData.pl line 497. And the program will sit in that loop forever, spitting out this warning/error to STDOUT. How do I trap this and DIE with an error message? -- Regards, Faber Fedor President Linux New Jersey, Inc. 908-320-0357 800-706-0701 http://www.linuxnj.com -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. From fiedlert at gmail.com Thu Oct 4 17:22:11 2007 From: fiedlert at gmail.com (Ted Fiedler) Date: Thu, 4 Oct 2007 20:22:11 -0400 Subject: [ABE.pm] trapping warnings In-Reply-To: <20071005000356.GA16111@neptune.faber.nom> References: <20071005000356.GA16111@neptune.faber.nom> Message-ID: <814422ce0710041722n12d7f8edof630d4e723d13e39@mail.gmail.com> $SIG{__DIE__} = \&customDie; $SIG{__WARN__} = \&customWarn; that should do the trick. and in sub customDie { print $LOG "Im dying: $!\n"; exit 1; } with a similar customWarn... Assuming of course that you have $LOG open for writing :) On 10/4/07, Faber J. Fedor wrote: > > I've got some code like this: > > $sum = $indexTable2->elm($i, "weight"); > while ($sum <= $captPercentile) { > $sum += $indexTable2->elm($i+1, "weight"); > $bottom_count ++; > $i++; > } > > If indexTable2 is empty (it should never be, but hey this is RL), I get > errors like: > > Row index out of range [0..-1]Use of uninitialized value in addition (+) > at /home/sqa/bin/processMonthlyData.pl line 497. > > And the program will sit in that loop forever, spitting out this > warning/error to STDOUT. > > How do I trap this and DIE with an error message? > > > -- > > Regards, > > Faber Fedor > President > Linux New Jersey, Inc. > 908-320-0357 > 800-706-0701 > > http://www.linuxnj.com > > > > > -- > This message has been scanned for viruses and > dangerous content by MailScanner, and is > believed to be clean. > > _______________________________________________ > ABE-pm mailing list > ABE-pm at pm.org > http://mail.pm.org/mailman/listinfo/abe-pm > -- If you mess with a thing long enough, it'll break. -- Schmidt -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.pm.org/pipermail/abe-pm/attachments/20071004/3ea6574d/attachment.html From rjbs-perl-abe at lists.manxome.org Thu Oct 4 17:31:54 2007 From: rjbs-perl-abe at lists.manxome.org (Ricardo SIGNES) Date: Thu, 4 Oct 2007 20:31:54 -0400 Subject: [ABE.pm] trapping warnings In-Reply-To: <20071005000356.GA16111@neptune.faber.nom> References: <20071005000356.GA16111@neptune.faber.nom> Message-ID: <20071005003154.GB3495@zodiac.codesimply.com> * "Faber J. Fedor" [2007-10-04T20:03:56] > $sum = $indexTable2->elm($i, "weight"); > while ($sum <= $captPercentile) { > $sum += $indexTable2->elm($i+1, "weight"); > $bottom_count ++; > $i++; > } > > [ ... ] > Row index out of range [0..-1]Use of uninitialized value in addition (+) at > /home/sqa/bin/processMonthlyData.pl line 497. > [ ... ] > > How do I trap this and DIE with an error message? Rather than using an actual SIG{__?__} handler, consider catching that problem before it occurs: while ($sum <= $captPercentile) { my $next_value = $indexTable2->elm($i + 1, "weight"); confess "didn't get a positive number from table" unless $next_value > 0; $sum += $next_value; $bottom_count++ $i++; } -- rjbs From faber at linuxnj.com Thu Oct 4 19:37:34 2007 From: faber at linuxnj.com (Faber J. Fedor) Date: Thu, 4 Oct 2007 22:37:34 -0400 Subject: [ABE.pm] trapping warnings In-Reply-To: <20071005003154.GB3495@zodiac.codesimply.com> References: <20071005000356.GA16111@neptune.faber.nom> <20071005003154.GB3495@zodiac.codesimply.com> Message-ID: <20071005023734.GB16111@neptune.faber.nom> On 04/10/07 20:31 -0400, Ricardo SIGNES wrote: > * "Faber J. Fedor" [2007-10-04T20:03:56] > > How do I trap this and DIE with an error message? > > Rather than using an actual SIG{__?__} handler, consider catching that problem > before it occurs: I like both ideas. Ted's to catch the error in the first place and your's to fix it once it's been caught. -- Regards, Faber Fedor President Linux New Jersey, Inc. 908-320-0357 800-706-0701 http://www.linuxnj.com -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. From rjbs-perl-abe at lists.manxome.org Fri Oct 5 04:26:12 2007 From: rjbs-perl-abe at lists.manxome.org (Ricardo SIGNES) Date: Fri, 5 Oct 2007 07:26:12 -0400 Subject: [ABE.pm] trapping warnings In-Reply-To: <20071005023734.GB16111@neptune.faber.nom> References: <20071005000356.GA16111@neptune.faber.nom> <20071005003154.GB3495@zodiac.codesimply.com> <20071005023734.GB16111@neptune.faber.nom> Message-ID: <20071005112611.GA30141@zodiac.codesimply.com> * "Faber J. Fedor" [2007-10-04T22:37:34] > On 04/10/07 20:31 -0400, Ricardo SIGNES wrote: > > * "Faber J. Fedor" [2007-10-04T20:03:56] > > > How do I trap this and DIE with an error message? > > > > Rather than using an actual SIG{__?__} handler, consider catching that > > problem before it occurs: > > I like both ideas. Ted's to catch the error in the first place and > your's to fix it once it's been caught. Well, but the code that I provided would never generate a warning... or at least that was the intent. You probably want a ||0 in there. I would suggest that in 99.999% of all cases, the correct answer is to avoid the warning, not to write a sigwarn. In fact, I think the ONLY time I have ever written a __WARN__ signal handler has been in tests, to ensure that a warning occurs when I want it. SIG{__DIE__} is only overkill 97% of the time. Usually the answer is eval. -- rjbs From fiedlert at gmail.com Fri Oct 5 07:53:02 2007 From: fiedlert at gmail.com (Ted Fiedler) Date: Fri, 5 Oct 2007 10:53:02 -0400 Subject: [ABE.pm] trapping warnings In-Reply-To: <20071005112611.GA30141@zodiac.codesimply.com> References: <20071005000356.GA16111@neptune.faber.nom> <20071005003154.GB3495@zodiac.codesimply.com> <20071005023734.GB16111@neptune.faber.nom> <20071005112611.GA30141@zodiac.codesimply.com> Message-ID: <814422ce0710050753i1a10d821x26af7e574352e4ab@mail.gmail.com> > > > > SIG{__DIE__} is only overkill 97% of the time. Usually the answer is > eval. Just for the record I wholeheartedly agree with this statement. Ted -- > rjbs > _______________________________________________ > ABE-pm mailing list > ABE-pm at pm.org > http://mail.pm.org/mailman/listinfo/abe-pm > -- If you mess with a thing long enough, it'll break. -- Schmidt -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.pm.org/pipermail/abe-pm/attachments/20071005/838af1c5/attachment.html From faber at linuxnj.com Fri Oct 5 10:19:02 2007 From: faber at linuxnj.com (Faber J. Fedor) Date: Fri, 5 Oct 2007 13:19:02 -0400 Subject: [ABE.pm] Prompting users Message-ID: <20071005171902.GA19418@neptune.faber.nom> What's the best way to prompt for user input a la CPAN? Use $name = ? -- Regards, Faber Fedor President Linux New Jersey, Inc. 908-320-0357 800-706-0701 http://www.linuxnj.com -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. From waltman at pobox.com Fri Oct 5 10:28:20 2007 From: waltman at pobox.com (Walt Mankowski) Date: Fri, 5 Oct 2007 13:28:20 -0400 Subject: [ABE.pm] Prompting users In-Reply-To: <20071005171902.GA19418@neptune.faber.nom> References: <20071005171902.GA19418@neptune.faber.nom> Message-ID: <20071005172820.GN13675@mawode.com> On Fri, Oct 05, 2007 at 01:19:02PM -0400, Faber J. Fedor wrote: > > What's the best way to prompt for user input a la CPAN? > Use $name = ? You know, the cool thing about open source is if you want to do something like have input work the way it does in CPAN.pm, you can just look in CPAN.pm and see how it does its magic. :) It appears to use Term::ReadLine (or maybe one of its subclasses; it's a bit complicated). Just search for "sub shell" to see how it works. Walt From faber at linuxnj.com Fri Oct 5 10:57:44 2007 From: faber at linuxnj.com (Faber J. Fedor) Date: Fri, 5 Oct 2007 13:57:44 -0400 Subject: [ABE.pm] Prompting users In-Reply-To: <20071005172820.GN13675@mawode.com> References: <20071005171902.GA19418@neptune.faber.nom> <20071005172820.GN13675@mawode.com> Message-ID: <20071005175744.GB19418@neptune.faber.nom> On 05/10/07 13:28 -0400, Walt Mankowski wrote: > On Fri, Oct 05, 2007 at 01:19:02PM -0400, Faber J. Fedor wrote: > > > > What's the best way to prompt for user input a la CPAN? > > Use $name = ? > > You know, the cool thing about open source is if you want to do > something like have input work the way it does in CPAN.pm, you can > just look in CPAN.pm and see how it does its magic. :) I was looking in CPAN/FirstTime.pm to see how they did it; they use prompt(). I couldn't find where prompt() came from. I assume it's in one of the other CPAN modules; if that's correct I don't want to import a bunch of CPAN modules for one function. I googled for "perl interactive prompting" and variations, finding nothing worthwhile. I consulted my O'Reilly Perl Bookshelf and all they mentioned was . Hence my posting here. I'll look into Term::Readline. -- Regards, Faber Fedor President Linux New Jersey, Inc. 908-320-0357 800-706-0701 http://www.linuxnj.com -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. From rjbs-perl-abe at lists.manxome.org Fri Oct 5 11:03:02 2007 From: rjbs-perl-abe at lists.manxome.org (Ricardo SIGNES) Date: Fri, 5 Oct 2007 14:03:02 -0400 Subject: [ABE.pm] Prompting users In-Reply-To: <20071005172820.GN13675@mawode.com> References: <20071005171902.GA19418@neptune.faber.nom> <20071005172820.GN13675@mawode.com> Message-ID: <20071005180302.GB3056@knight.office.icgroup.com> * Walt Mankowski [2007-10-05T13:28:20] > On Fri, Oct 05, 2007 at 01:19:02PM -0400, Faber J. Fedor wrote: > > > > What's the best way to prompt for user input a la CPAN? > > Use $name = ? > > It appears to use Term::ReadLine (or maybe one of its subclasses; it's > a bit complicated). Just search for "sub shell" to see how it works. IO::Prompt is pretty neat, although I recall having problems using it on 5.6. You might not care. -- rjbs From rjbs-perl-abe at lists.manxome.org Fri Oct 5 18:38:02 2007 From: rjbs-perl-abe at lists.manxome.org (Ricardo SIGNES) Date: Fri, 5 Oct 2007 21:38:02 -0400 Subject: [ABE.pm] UG News--MAKE's Latest Books Message-ID: <20071006013802.GA3487@knight.cable.rcn.com> Let me know if I should let her know... ----- Forwarded message from Marsee Henon ----- MAKE has a few new books coming out this month and I wanted to get an early start looking for reviewers. Please let me know if you or any of your members are interested in the following titles: Making Things Talk http://www.oreilly.com/catalog/9780596510510/ Illustrated Guide to Astronomical Wonders http://www.oreilly.com/catalog/9780596526856/ The Best of MAKE http://www.oreilly.com/catalog/9780596514280/ Eccentric Cubicle? http://www.oreilly.com/catalog/9780596510541/ There's also a new issue of Make Magazine featuring "DIY Wheels" http://www.oreilly.com/catalog/9780596513870/index.html If you live in the Austin Area be sure to check out the Maker Faire October 20-21 at the Travis County Expo Center, Austin, Texas. The hours on Saturday are 10am-6pm and Sunday 10am-5pm. http://www.makerfaire.com/ I'll be working in the Make store so stop by and say hi if you're going to be there. --Marsee ----- End forwarded message ----- -- rjbs From rjbs-perl-abe at lists.manxome.org Tue Oct 16 19:15:37 2007 From: rjbs-perl-abe at lists.manxome.org (Ricardo SIGNES) Date: Tue, 16 Oct 2007 22:15:37 -0400 Subject: [ABE.pm] we have a wiki again! Message-ID: <20071017021537.GA998@knight> Thanks to Good People, we have a wiki again! It's running SocialText, the uber-powerful Perl-based wiki that hosts The Perl Five wiki, among other things. Right now you can find it here: http://www.perlfoundation.org/abe-pm You can make a new account or use your OpenID. Go nuts! Soonish, abe.pm.org will point to it. -- rjbs From faber at linuxnj.com Fri Oct 19 16:18:04 2007 From: faber at linuxnj.com (Faber J. Fedor) Date: Fri, 19 Oct 2007 19:18:04 -0400 Subject: [ABE.pm] Any Catalyst users in here? Message-ID: <20071019231804.GA8813@neptune.faber.nom> Does anyone in here use Catalyst framework? I need some basic help; I can't even get a "Hello world" page to display. -- Regards, Faber Fedor President Linux New Jersey, Inc. 908-320-0357 800-706-0701 http://www.linuxnj.com -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. From rjbs-perl-abe at lists.manxome.org Fri Oct 19 17:32:58 2007 From: rjbs-perl-abe at lists.manxome.org (Ricardo SIGNES) Date: Fri, 19 Oct 2007 20:32:58 -0400 Subject: [ABE.pm] Any Catalyst users in here? In-Reply-To: <20071019231804.GA8813@neptune.faber.nom> References: <20071019231804.GA8813@neptune.faber.nom> Message-ID: <20071020003258.GA11949@zodiac.codesimply.com> * "Faber J. Fedor" [2007-10-19T19:18:04] > Does anyone in here use Catalyst framework? I need some basic help; I > can't even get a "Hello world" page to display. Have you gone through Catalyst::Manual::Tutorial? http://search.cpan.org/~jrockway/Catalyst-Manual-5.701003/lib/Catalyst/Manual/Tutorial.pod I generally use CGI::Application for me, Mason and Catalyst for work. -- rjbs From faber at linuxnj.com Fri Oct 19 20:14:40 2007 From: faber at linuxnj.com (Faber J. Fedor) Date: Fri, 19 Oct 2007 23:14:40 -0400 Subject: [ABE.pm] Any Catalyst users in here? In-Reply-To: <20071020003258.GA11949@zodiac.codesimply.com> References: <20071019231804.GA8813@neptune.faber.nom> <20071020003258.GA11949@zodiac.codesimply.com> Message-ID: <20071020031440.GA9649@neptune.faber.nom> On 19/10/07 20:32 -0400, Ricardo SIGNES wrote: > * "Faber J. Fedor" [2007-10-19T19:18:04] > > Does anyone in here use Catalyst framework? I need some basic help; I > > can't even get a "Hello world" page to display. > > Have you gone through Catalyst::Manual::Tutorial? > > http://search.cpan.org/~jrockway/Catalyst-Manual-5.701003/lib/Catalyst/Manual/Tutorial.pod Numerous times! It was no better than listening to the lectures in Houston and PGH. :-( I finally grokked it because of raptor's intro (http://dev.catalyst.perl.org/wiki/YetAnotherCatalystIntro). It seems I can decipher ESL (For step one we create in "gbook/root/" templates. additem.tt with the following content ) better than than jrockway's hardcore geek (http://cpansearch.perl.org/~jrockway/Catalyst-Manual/lib/Catalyst/Manual/Intro.pod#Views) that's said as an afterthought ("Also, be sure to put the template under the directory specified in $c->config->{root}, or you'll end up looking at the debug screen.") So I can now do a "Hello World" in Catalyst. Huzzah! Tomorrow, Forms and YAML! -- Regards, Faber Fedor President Linux New Jersey, Inc. 908-320-0357 800-706-0701 http://www.linuxnj.com -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. From fiedlert at gmail.com Sat Oct 20 04:15:19 2007 From: fiedlert at gmail.com (Ted Fiedler) Date: Sat, 20 Oct 2007 07:15:19 -0400 Subject: [ABE.pm] perl5.10 Message-ID: <814422ce0710200415g461a4de3lbc0e4c231d252c6f@mail.gmail.com> Looks like this is getting closer - I built bleadperl this morning and the binaries were 5.10.0. Ted -- If you mess with a thing long enough, it'll break. -- Schmidt -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.pm.org/pipermail/abe-pm/attachments/20071020/030ed187/attachment.html From faber at linuxnj.com Sat Oct 20 07:48:53 2007 From: faber at linuxnj.com (Faber J. Fedor) Date: Sat, 20 Oct 2007 10:48:53 -0400 Subject: [ABE.pm] What are my options here? Message-ID: <20071020144853.GB12290@neptune.faber.nom> I've got a webapp that needs to be written yesterday. The webapp will allow the enduser to set numerous options, save the configurations, and then run a script that is already in production. Eventually, the webapp will somehow execute a native Windows app or two, but that's down the road. Everything I read says Catalyst is perfect for this kind of thing and after playing with it, I agree. My problem is Catalyst requires Perl 5.8.1 or higher and I'm stuck at 5.8.0. Upgrading the system is on the todo list. It's not a simple matter of simply upgrading the OS, though; alot of testing is involved. I could install a parallel version of Perl and all the modules and Catalyst but I can see where that's going to cause a lot of frustration keeping the two separated, not the least in my mind. Besides, that just doesn't like a Good Thing to do on a production system. I could code the thing from scratch but that's going to slow me down and the webapp should then be recoded in the future when I do upgrade things. And I know it won't be as bullet-proof as a Catalyst-based webapp. I think I'll have to code it by hand. Anyone else have a better suggestion? -- Regards, Faber Fedor President Linux New Jersey, Inc. 908-320-0357 800-706-0701 http://www.linuxnj.com -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. From rjbs-perl-abe at lists.manxome.org Sat Oct 20 10:53:02 2007 From: rjbs-perl-abe at lists.manxome.org (Ricardo SIGNES) Date: Sat, 20 Oct 2007 13:53:02 -0400 Subject: [ABE.pm] What are my options here? In-Reply-To: <20071020144853.GB12290@neptune.faber.nom> References: <20071020144853.GB12290@neptune.faber.nom> Message-ID: <20071020175302.GB24916@knight> * "Faber J. Fedor" [2007-10-20T10:48:53] > I've got a webapp that needs to be written yesterday. The webapp will > allow the enduser to set numerous options, save the configurations, and > then run a script that is already in production. Eventually, the webapp > will somehow execute a native Windows app or two, but that's down the > road. What kind of login does it need? > I think I'll have to code it by hand. Anyone else have a better suggestion? CGI::Application. -- rjbs From faber at linuxnj.com Sat Oct 20 11:58:06 2007 From: faber at linuxnj.com (Faber J. Fedor) Date: Sat, 20 Oct 2007 14:58:06 -0400 Subject: [ABE.pm] What are my options here? In-Reply-To: <20071020175302.GB24916@knight> References: <20071020144853.GB12290@neptune.faber.nom> <20071020175302.GB24916@knight> Message-ID: <20071020185806.GA13162@neptune.faber.nom> On 20/10/07 13:53 -0400, Ricardo SIGNES wrote: > * "Faber J. Fedor" [2007-10-20T10:48:53] > > I've got a webapp that needs to be written yesterday. The webapp will > > allow the enduser to set numerous options, save the configurations, and > > then run a script that is already in production. Eventually, the webapp > > will somehow execute a native Windows app or two, but that's down the > > road. > > What kind of login does it need? Technically, none. (I assume you mean user autnetication/authorization.) > > I think I'll have to code it by hand. Anyone else have a better suggestion? > > CGI::Application. Okay. -- Regards, Faber Fedor President Linux New Jersey, Inc. 908-320-0357 800-706-0701 http://www.linuxnj.com -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. From rjbs-perl-abe at lists.manxome.org Wed Oct 24 07:10:15 2007 From: rjbs-perl-abe at lists.manxome.org (Ricardo SIGNES) Date: Wed, 24 Oct 2007 10:10:15 -0400 Subject: [ABE.pm] next dinner date; hacking sometime? Message-ID: <20071024141015.GA14618@knight> November 7 will be the first Wedenesday of November, and thus it will be time for dinner. McGrady's? I can't get enough of those wings. I didn't have my PPW slides done to show them off before I went, but I *did* get them done by PPW, so now I have them. If anyone is interested, I'll run through my App::Cmd slides. App::Cmd is lots of fun to use, and everyone should use it and tell me what could be improved. Speaking of collaboration, I'm hoping that I can set aside some regualr slots of time over the next few months to get work done on projects that need it. If anybody is interested on hacking on Stuff with me, possibly over a beer or nachos or something, let me know. I may post likely hacking topics, if anyone is interested. -- rjbs From fiedlert at gmail.com Wed Oct 24 07:54:35 2007 From: fiedlert at gmail.com (Ted Fiedler) Date: Wed, 24 Oct 2007 10:54:35 -0400 Subject: [ABE.pm] next dinner date; hacking sometime? In-Reply-To: <20071024141015.GA14618@knight> References: <20071024141015.GA14618@knight> Message-ID: <814422ce0710240754n573d4980j7df440daf755087e@mail.gmail.com> On 10/24/07, Ricardo SIGNES wrote: > > > November 7 will be the first Wedenesday of November, and thus it will be > time > for dinner. McGrady's? I can't get enough of those wings. I cannot make the 7th, my wife will just be getting back into town @ 5 or 6 PM and I cant just drop and run. > > > Speaking of collaboration, I'm hoping that I can set aside some regualr > slots > of time over the next few months to get work done on projects that need > it. If > anybody is interested on hacking on Stuff with me, possibly over a beer or > nachos or something, let me know. I may post likely hacking topics, if > anyone > is interested. Im good for some collaboration. If you can deal w/ my lackluster perl hacking habits :) Speaking of which, im working on an ETL tool that uses ini files for table mappings and for db connections. It also uses what I call autokeys. If a table has NO unique keys, you give it a few columns which together make up a unique set and uses that as a key. If I post it somewhere would anyone be willing to give it a go and make some suggestions. Its pretty rough, but it works fairly solidly :) Im working on adding syncing csv files at the moment. Mostly I use it for syncing tables in heterogeneous db environments mysql to sqlserver, sqlserver to informix, anyting to CSV , etc... -- > rjbs > _______________________________________________ > ABE-pm mailing list > ABE-pm at pm.org > http://mail.pm.org/mailman/listinfo/abe-pm > -- If you mess with a thing long enough, it'll break. -- Schmidt -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.pm.org/pipermail/abe-pm/attachments/20071024/8ed0cf94/attachment.html From tfreedman at iqep.com Wed Oct 24 09:01:11 2007 From: tfreedman at iqep.com (Tom Freedman) Date: Wed, 24 Oct 2007 12:01:11 -0400 Subject: [ABE.pm] next dinner date; hacking sometime? In-Reply-To: <814422ce0710240754n573d4980j7df440daf755087e@mail.gmail.com> References: <20071024141015.GA14618@knight> <814422ce0710240754n573d4980j7df440daf755087e@mail.gmail.com> Message-ID: ________________________________ From: abe-pm-bounces+tfreedman=iqep.com at pm.org [mailto:abe-pm-bounces+tfreedman=iqep.com at pm.org] On Behalf Of Ted Fiedler I cannot make the 7th, my wife will just be getting back into town @ 5 or 6 PM and I cant just drop and run. C'mon, which is more important, kryptonite wings or your marriage? Wait, don't answer that... Speaking of which, im working on an ETL tool that uses ini files for table mappings and for db connections. It also uses what I call autokeys. If a table has NO unique keys, you give it a few columns which together make up a unique set and uses that as a key. If I post it somewhere would anyone be willing to give it a go and make some suggestions. Its pretty rough, but it works fairly solidly :) Im working on adding syncing csv files at the moment. Mostly I use it for syncing tables in heterogeneous db environments mysql to sqlserver, sqlserver to informix, anyting to CSV , etc... The type of key you're describing is known as a "compound primary key". From the name, I'd assume an "autokey" was an automatically incremented numeric key (an "identity" column in SQL Server; an "auto_increment" in MySQL). I'd be happy to have a look through the code. Database theory was my primary focus in college, and I've worked with a few of them, so I might spot something you hadn't thought of. -Tom ________________________________ Confidentiality Notice: This e-mail message, including any attachments, is for the sole use of the intended recipient(s) and may contain confidential and/or privileged information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender immediately by reply e-mail and destroy all copies of the original message. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.pm.org/pipermail/abe-pm/attachments/20071024/3d4bc9b8/attachment.html From rjbs-perl-abe at lists.manxome.org Wed Oct 24 09:51:54 2007 From: rjbs-perl-abe at lists.manxome.org (Ricardo SIGNES) Date: Wed, 24 Oct 2007 12:51:54 -0400 Subject: [ABE.pm] next dinner date; hacking sometime? In-Reply-To: References: <20071024141015.GA14618@knight> <814422ce0710240754n573d4980j7df440daf755087e@mail.gmail.com> Message-ID: <20071024165154.GA16746@knight> * Tom Freedman [2007-10-24T12:01:11] > ________________________________ > From: abe-pm-bounces+tfreedman=iqep.com at pm.org [mailto:abe-pm-bounces+tfreedman=iqep.com at pm.org] On Behalf Of Ted Fiedler > I cannot make the 7th, my wife will just be getting back into town @ 5 or 6 PM and I cant just drop and run. > > C'mon, which is more important, kryptonite wings or your marriage? Wait, don't answer that... Did you recently change email software? It's impossible to tell what is in reply to what, in the text version of your message. -- rjbs From jkeen at verizon.net Wed Oct 24 14:29:54 2007 From: jkeen at verizon.net (James E Keenan) Date: Wed, 24 Oct 2007 17:29:54 -0400 Subject: [ABE.pm] next dinner date; hacking sometime? In-Reply-To: References: Message-ID: <44A1ECB5-9C9C-4E10-8C85-557D2DDD5F1B@verizon.net> On Oct 24, 2007, at 3:00 PM, abe-pm-request at pm.org wrote: > > > Message: 1 > Date: Wed, 24 Oct 2007 10:10:15 -0400 > From: Ricardo SIGNES > Subject: [ABE.pm] next dinner date; hacking sometime? > To: abe-pm at pm.org > Message-ID: <20071024141015.GA14618 at knight> > Content-Type: text/plain; charset=us-ascii > > > If > anybody is interested on hacking on Stuff with me, possibly over a > beer or > nachos or something, let me know. Do I hear the work 'hackathon' in there somewhere? From rjbs-perl-abe at lists.manxome.org Wed Oct 24 15:48:15 2007 From: rjbs-perl-abe at lists.manxome.org (Ricardo SIGNES) Date: Wed, 24 Oct 2007 18:48:15 -0400 Subject: [ABE.pm] next dinner date; hacking sometime? In-Reply-To: <44A1ECB5-9C9C-4E10-8C85-557D2DDD5F1B@verizon.net> References: <44A1ECB5-9C9C-4E10-8C85-557D2DDD5F1B@verizon.net> Message-ID: <20071024224815.GA21662@knight> * James E Keenan [2007-10-24T17:29:54] > > If anybody is interested on hacking on Stuff with me, possibly over a beer > > or nachos or something, let me know. > > Do I hear the work 'hackathon' in there somewhere? Nope. "Hackathon" sounds like some kind of, say, "hacking marathon," and I don't have the stamina for that sort of thing in my old age. Also, the hackathons have all been "everyone is welcome to show up as you like and get instructed in doing stuff we need," whereas I'm saying, "if some people are interested, maybe you can come by my place and we'll talk about some ideas and write a couple spikes." -- rjbs From faber at linuxnj.com Wed Oct 24 18:30:41 2007 From: faber at linuxnj.com (Faber J. Fedor) Date: Wed, 24 Oct 2007 21:30:41 -0400 Subject: [ABE.pm] next dinner date; hacking sometime? In-Reply-To: <20071024141015.GA14618@knight> References: <20071024141015.GA14618@knight> Message-ID: <20071025013041.GA19521@neptune.faber.nom> On 24/10/07 10:10 -0400, Ricardo SIGNES wrote: > November 7 will be the first Wedenesday of November, and thus it will be time > for dinner. McGrady's? I can't get enough of those wings. I keep telling youse guys: they'll deliver to Gutes! > I didn't have my PPW slides done to show them off before I went, but I *did* > get them done by PPW, so now I have them. If anyone is interested, I'll run > through my App::Cmd slides. App::Cmd is lots of fun to use, and everyone > should use it and tell me what could be improved. I'm interested cuz' I missed that one. I did catch the Sub::Exporter one and *now* I understand it and why I'd want to use it. > Speaking of collaboration, I'm hoping that I can set aside some regualr slots > of time over the next few months to get work done on projects that need it. If > anybody is interested on hacking on Stuff with me, possibly over a beer or > nachos or something, let me know. I may post likely hacking topics, if anyone > is interested. I'm interested. How useful I'll be remains to be seen. BTW, I found that ACID cigar of yours. I'll bring it to dinner. -- Regards, Faber Fedor President Linux New Jersey, Inc. 908-320-0357 800-706-0701 http://www.linuxnj.com -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. From rjbs-perl-abe at lists.manxome.org Wed Oct 24 18:56:04 2007 From: rjbs-perl-abe at lists.manxome.org (Ricardo SIGNES) Date: Wed, 24 Oct 2007 21:56:04 -0400 Subject: [ABE.pm] next dinner date; hacking sometime? In-Reply-To: <20071025013041.GA19521@neptune.faber.nom> References: <20071024141015.GA14618@knight> <20071025013041.GA19521@neptune.faber.nom> Message-ID: <20071025015604.GA24027@knight> * "Faber J. Fedor" [2007-10-24T21:30:41] > On 24/10/07 10:10 -0400, Ricardo SIGNES wrote: > > November 7 will be the first Wedenesday of November, and thus it will be > > time for dinner. McGrady's? I can't get enough of those wings. > > I keep telling youse guys: they'll deliver to Gutes! In fact, without Ted, I am not going to eat kryptonite wings, I think -- nobody else would save me from eating 8-9 of them, and I'm afraid of what might happen. Would people prefer Gutes instead? > > I didn't have my PPW slides done to show them off before I went, but I > > *did* get them done by PPW, so now I have them. If anyone is interested, > > I'll run through my App::Cmd slides. App::Cmd is lots of fun to use, and > > everyone should use it and tell me what could be improved. > > I'm interested cuz' I missed that one. I did catch the Sub::Exporter > one and *now* I understand it and why I'd want to use it. Yaaaay! > BTW, I found that ACID cigar of yours. I'll bring it to dinner. Ha! Cool. -- rjbs From faber at linuxnj.com Fri Oct 26 10:30:50 2007 From: faber at linuxnj.com (Faber J. Fedor) Date: Fri, 26 Oct 2007 13:30:50 -0400 Subject: [ABE.pm] My first enclosure doesn't work. :-( Message-ID: <20071026173050.GA30227@neptune.faber.nom> I'm porting a script to a webapp. One of the changes I want to do is to dynamically generate an if-elsif. After thinking it through, it seems like an enclosure would do what I want but I can't get it to work. :-( I want to dynamically generate this from a hash: if ($capt < 100) {return (3.0);} elsif (($capt >= 100) && ($capt < 250)) {return (1.5);} ... elsif (($capt >= 10000) && ($capt < 50000)) {return (0.01);} elsif ($capt >= 50000) {return (0.005);} In my enclosure, I generate my $stmt much as I would build an SQL statement (yes, I know about DBIC; now get off my lawn!) so that, at the end of the enclosure, if I 'print $stmt' I see a legit if-elsif statement. Now what? At the end of my enclosure, I say 'return sub { $stmt };' or 'return sub { eval($stmt) };'. If I then do a 'print make_if_elsif(300)' I get 'CODE(0x8096228)' instead of the expected '1.0'. What am I doing wrong? You can find my script at http://www.faberfedor.com/enclosure_example.pl -- Regards, Faber Fedor President Linux New Jersey, Inc. 908-320-0357 800-706-0701 http://www.linuxnj.com -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. From fiedlert at gmail.com Fri Oct 26 11:05:55 2007 From: fiedlert at gmail.com (Ted Fiedler) Date: Fri, 26 Oct 2007 14:05:55 -0400 Subject: [ABE.pm] My first enclosure doesn't work. :-( In-Reply-To: <20071026173050.GA30227@neptune.faber.nom> References: <20071026173050.GA30227@neptune.faber.nom> Message-ID: <814422ce0710261105t1fa88fd7gac5604344486bd45@mail.gmail.com> Aside from doing the calculations - I would go with an approach something like this. Im in a meeting so I didn't have time to work the calculations in... Ted ___ Code Below ___ #!/usr/bin/perl use strict; use warnings; sub make_if_elsif { # This is the code we are trying to emulate with our enclosure my $capt = shift; #personally I would use something like this, but thats neither here nor there :) #return qq #|( $capt < 100 ) ? '3.0' : #( ($capt >= 100) and ($capt < 250) ) ? '1.5' : #( ($capt >= 10000) and ($capt < 50000) ) ? '0.01' : #'0.00'|; return qq| if ($capt eq "") {return (0.0);} elsif ($capt < 100) {return (3.0);} elsif (($capt >= 100) && ($capt < 250)) {return (1.5);} elsif (($capt >= 250) && ($capt < 500)) {return (1.0);} elsif (($capt >= 500) && ($capt < 750)) {return (0.75);} elsif (($capt >= 750) && ($capt < 1000)) {return (0.5);} elsif (($capt >= 1000) && ($capt < 2500)) {return (0.25);} elsif (($capt >= 2500) && ($capt < 5000)) {return (0.15);} elsif (($capt >= 5000) && ($capt < 7500)) {return (0.05);} elsif (($capt >= 7500) && ($capt < 10000)) {return (0.025);} elsif (($capt >= 10000) && ($capt < 50000)) {return (0.01);} elsif ($capt >= 50000) {return (0.005);}\n|; } my %costCalcH = ( "50000" => 0.005, "10000" => 0.01, "7500 " => 0.025, "5000 " => 0.05, "2500 " => 0.15, "1000 " => 0.25, "750 " => 0.5, "500 " => 0.75, "250 " => 1.0, "100 " => 1.5, "0 " => 3.0, ); # if you print out $stmt, you get the if-elsif statment above. my $x = make_if_elsif(300); print $x ; $x = make_if_elsif(5000); print $x ; -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.pm.org/pipermail/abe-pm/attachments/20071026/f31ca04b/attachment.html From faber at linuxnj.com Fri Oct 26 12:10:06 2007 From: faber at linuxnj.com (Faber J. Fedor) Date: Fri, 26 Oct 2007 15:10:06 -0400 Subject: [ABE.pm] My first enclosure doesn't work. :-( In-Reply-To: <814422ce0710261105t1fa88fd7gac5604344486bd45@mail.gmail.com> References: <20071026173050.GA30227@neptune.faber.nom> <814422ce0710261105t1fa88fd7gac5604344486bd45@mail.gmail.com> Message-ID: <20071026191006.GA30729@neptune.faber.nom> On 26/10/07 14:05 -0400, Ted Fiedler wrote: > Aside from doing the calculations - I would go with an approach something > like this. Im in a meeting so I didn't have time to work the calculations > in... > > Ted > > ___ Code Below ___ > > #!/usr/bin/perl > use strict; > use warnings; > > sub make_if_elsif { > # This is the code we are trying to emulate with our enclosure > my $capt = shift; > > #personally I would use something like this, but thats neither here nor > there :) > #return qq > #|( $capt < 100 ) ? '3.0' : > #( ($capt >= 100) and ($capt < 250) ) ? '1.5' : > #( ($capt >= 10000) and ($capt < 50000) ) ? '0.01' : > #'0.00'|; I'll try it, but the main thing I need to do is to make the if-elsif variable, both in $key and $value values as well as the number of elsif's, e.g. no harcoding of the if-elsifs. -- Regards, Faber Fedor President Linux New Jersey, Inc. 908-320-0357 800-706-0701 http://www.linuxnj.com -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. From waltman at pobox.com Fri Oct 26 12:46:55 2007 From: waltman at pobox.com (Walt Mankowski) Date: Fri, 26 Oct 2007 15:46:55 -0400 Subject: [ABE.pm] My first enclosure doesn't work. :-( In-Reply-To: <20071026173050.GA30227@neptune.faber.nom> References: <20071026173050.GA30227@neptune.faber.nom> Message-ID: <20071026194655.GF17222@mawode.com> On Fri, Oct 26, 2007 at 01:30:50PM -0400, Faber J. Fedor wrote: > I'm porting a script to a webapp. One of the changes I want to do is to > dynamically generate an if-elsif. After thinking it through, it seems > like an enclosure would do what I want but I can't get it to work. :-( > > I want to dynamically generate this from a hash: > > if ($capt < 100) > {return (3.0);} > elsif (($capt >= 100) && ($capt < 250)) > {return (1.5);} > ... > elsif (($capt >= 10000) && ($capt < 50000)) > {return (0.01);} > elsif ($capt >= 50000) > {return (0.005);} > > In my enclosure, I generate my $stmt much as I would build an SQL > statement (yes, I know about DBIC; now get off my lawn!) so that, at the > end of the enclosure, if I 'print $stmt' I see a legit if-elsif > statement. > > Now what? At the end of my enclosure, I say 'return sub { $stmt };' or > 'return sub { eval($stmt) };'. If I then do a 'print > make_if_elsif(300)' I get 'CODE(0x8096228)' instead of the expected > '1.0'. > > What am I doing wrong? > > You can find my script at http://www.faberfedor.com/enclosure_example.pl What are you doing wrong? Well, for starters, whenever you see a long string of if/elses like that, you should try to see if you can replace it with a loop, or something that's table-driven. Trying to auto-generate the code for the if/elses is just making an already bad situation even more complex than it needs to be. The original code is also more complex than it needs to be because you're checking the lower and upper bound for each range. Since there aren't any holes in the ranges, you only need to check the upper range. I also don't understand why you want to use a hash when it seems simpler to me to use an array. I don't know what an "enclosure" is, but this seems a much simpler solution to your problem: #!/usr/bin/perl -wl use strict; print costCalc($ARGV[0]); sub costCalc { my ($capt) = @_; my @costCalcArr = ( [50000 => 0.005], [10000 => 0.01], [7500 => 0.025], [5000 => 0.05], [2500 => 0.15], [1000 => 0.25], [750 => 0.5], [500 => 0.75], [250 => 1.0], [100 => 1.5], ); return 0.0 if $capt eq ""; for my $ar (@costCalcArr) { return $ar->[1] if $capt >= $ar->[0]; } return 3.0; } I suppose you could try doing a binary search on the interval cutoffs, but with only 10 values it's probably not worth the trouble. You could also store the intervals in a binary tree or a range tree, but again, it's probably not worth the trouble. Walt From faber at linuxnj.com Fri Oct 26 13:25:40 2007 From: faber at linuxnj.com (Faber J. Fedor) Date: Fri, 26 Oct 2007 16:25:40 -0400 Subject: [ABE.pm] My first en^H^Hclosure doesn't work. :-( In-Reply-To: <20071026194655.GF17222@mawode.com> References: <20071026173050.GA30227@neptune.faber.nom> <20071026194655.GF17222@mawode.com> Message-ID: <20071026202540.GB30729@neptune.faber.nom> On 26/10/07 15:46 -0400, Walt Mankowski wrote: > What are you doing wrong? Well, for starters, whenever you see a long > string of if/elses like that, you should try to see if you can replace > it with a loop, or something that's table-driven. Trying to > auto-generate the code for the if/elses is just making an already bad > situation even more complex than it needs to be. Yes, I know. > The original code is also more complex than it needs to be because > you're checking the lower and upper bound for each range. Since there > aren't any holes in the ranges, you only need to check the upper > range. Yes, I know. I've already done that as well (see below). The reason for the *example* is I didn't want to say "I want to reimplement this if-elsif construct' then show my code that checks only the upper range and have someone go "where's the elsif?". > I also don't understand why you want to use a hash when it seems > simpler to me to use an array. I like hashes? > I don't know what an "enclosure" is, but this seems a much simpler > solution to your problem: Sorry, "closure" not "enclosure". > for my $ar (@costCalcArr) { > return $ar->[1] if $capt >= $ar->[0]; > } Actually, what I implemented is very close to that: foreach my $key (sort { $b <=> $a } keys %costCalcH) { return $costCalcH{$key} if $capt >= $key; } the main difference being I don't trust my user to put the values in proper order. And the original question remains... -- Regards, Faber Fedor President Linux New Jersey, Inc. 908-320-0357 800-706-0701 http://www.linuxnj.com -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. From waltman at pobox.com Fri Oct 26 13:34:32 2007 From: waltman at pobox.com (Walt Mankowski) Date: Fri, 26 Oct 2007 16:34:32 -0400 Subject: [ABE.pm] My first en^H^Hclosure doesn't work. :-( In-Reply-To: <20071026202540.GB30729@neptune.faber.nom> References: <20071026173050.GA30227@neptune.faber.nom> <20071026194655.GF17222@mawode.com> <20071026202540.GB30729@neptune.faber.nom> Message-ID: <20071026203432.GG17222@mawode.com> On Fri, Oct 26, 2007 at 04:25:40PM -0400, Faber J. Fedor wrote: > The reason for the *example* is I didn't want to say "I want to > reimplement this if-elsif construct' then show my code that checks > only the upper range and have someone go "where's the elsif?". So instead you have people wondering why you have code there you don't need which is just making everything that much harder. > I like hashes? > > Actually, what I implemented is very close to that: > > foreach my $key (sort { $b <=> $a } keys %costCalcH) { > return $costCalcH{$key} if $capt >= $key; > } > > the main difference being I don't trust my user to put the values in > proper order. I was originally going to do that with hashes, but I didn't want the overhead of having to sort the keys on every call. Perhaps you could have a preprocessing step where on the first call you generate a sorted list from the hash? Speaking of which, you don't trust them to sort values, but you do trust them to enter perl hashes in the correct syntax? > And the original question remains... Guess I'm less interested in the original question since if can be solved in 2 lines of code in the alternate approach... :) Walt From faber at linuxnj.com Fri Oct 26 13:58:21 2007 From: faber at linuxnj.com (Faber J. Fedor) Date: Fri, 26 Oct 2007 16:58:21 -0400 Subject: [ABE.pm] My first en^H^Hclosure doesn't work. :-( In-Reply-To: <20071026203432.GG17222@mawode.com> References: <20071026173050.GA30227@neptune.faber.nom> <20071026194655.GF17222@mawode.com> <20071026202540.GB30729@neptune.faber.nom> <20071026203432.GG17222@mawode.com> Message-ID: <20071026205821.GA31492@neptune.faber.nom> On 26/10/07 16:34 -0400, Walt Mankowski wrote: > On Fri, Oct 26, 2007 at 04:25:40PM -0400, Faber J. Fedor wrote: > > the main difference being I don't trust my user to put the values in > > proper order. > > Speaking of which, you don't trust them to > sort values, but you do trust them to enter perl hashes in the correct > syntax? Yeah, right. I'm going to have my users enter a Perl hash... > > And the original question remains... > > Guess I'm less interested in the original question since if can be > solved in 2 lines of code in the alternate approach... :) And I want to expand my programming skills by writing a closure. -- Regards, Faber Fedor President Linux New Jersey, Inc. 908-320-0357 800-706-0701 http://www.linuxnj.com -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. From rjbs-perl-abe at lists.manxome.org Fri Oct 26 15:13:07 2007 From: rjbs-perl-abe at lists.manxome.org (Ricardo SIGNES) Date: Fri, 26 Oct 2007 18:13:07 -0400 Subject: [ABE.pm] My first enclosure doesn't work. :-( In-Reply-To: <20071026173050.GA30227@neptune.faber.nom> References: <20071026173050.GA30227@neptune.faber.nom> Message-ID: <20071026221307.GA6101@knight> * "Faber J. Fedor" [2007-10-26T13:30:50] > Now what? At the end of my enclosure, I say 'return sub { $stmt };' or > 'return sub { eval($stmt) };'. If I then do a 'print > make_if_elsif(300)' I get 'CODE(0x8096228)' instead of the expected > '1.0'. > > What am I doing wrong? Well, for one thing, you're even considering using string eval. :) I'm very confused by the code you pasted, so I'm going to potentially ignore all of it and write something vaguely related and see if it makes things any clearer. This code includes a routine call "make_bucketizer." It returns a closure that tells you what bucket something falls into. You pass it a number $n and it will bucketize into bins that are 10**$n wide. In other words, make_bucketizer(0) makes bins for 0-1, 1-2, ... 9-10. make_bucketizer(1) makes bins for 0-10, 10-20, ... 90-100. You can call the return routine with a number, and it returns the index of the bucket into which the number would fall. It also returns a second closure, which returns a list of pairs: all the buckets into which data were dumped, along with the data dumped there. Here's a usage example: my ($bucketize, $get_buckets) = make_bucketizer(2); $bucketize->(10); # in bucket 0, 0 - 100 $bucketize->(5020); # in bucket 50, 5000 - 5100 $bucketize->(1852); # in bucket 18, 1800 - 1900 $bucketize->(82); # in bucket 0, 0 - 100 my %content = $get_buckets->(); Dump(\%content); Produces: my $content = { 0 => [ 10, 82 ], 18 => [ 1852 ], 50 => [ 5020 ], }; This code does *not* dynamically generate an if/else tree. Basically, in dynamic Perl, you Just Don't Do That. if/else trees are literal structures, and you'd have to generate code and then eval it. This is a red flag the size of Texas. Instead, you'd build a data structure that can serve as a kind of dispatch table, or you eliminate the need for lookup at all by being highly generic. I'll provide two examples: # This make_bucketizer takes $n and returns a routine that can bucketize # arbitrary-sized numbers. sub make_bucketizer { my ($n) = @_; my $divisor = 10 ** $n; my %bucket; my $bucketizer = sub { my ($x) = @_; die "no negative numbers!" if $x < 0; # Note that buckets are [ m, n ) -- the zeroth bucket for $n = 0, for # example, includes 0 and runs up to anything less than 1, exclusive. my $bucket_number = int($x / $divisor); my $this_bucket = $bucket{ $bucket_number } ||= []; push @$this_bucket, $x; }; my $get_buckets = sub { %bucket }; return ($bucketizer, $get_buckets); } The example above avoids ever having to do a lookup, as it can always compute -- it's still a legitimate use of closures, because it closes usefully over both $n and %bucket. Let's say you want to make a lookup table, though, because on your processor, division is really, really slow. # This make_bucketizer takes $n and $num_buckets, and returns a routine that # can bucketize into $num_buckets buckets. sub make_bucketizer { my ($n, $num_buckets) = @_; my $multiplier = 10 ** $n; # I would probably write this with (map BLOCK LIST) but for the sake of # simplicity, here I use a loop. my @bins; for my $i (0 .. $num_buckets) { push @bins, $multiplier * ($num_buckets + 1); } # So now @bins is a list of upper-limits. my %bucket; my $bucketizer = sub { my ($x) = @_; die "no negative numbers!" if $x < 0; # Note that buckets are [ m, n ) -- the zeroth bucket for $n = 0, for # example, includes 0 and runs up to anything less than 1, exclusive. my $bucket_number; BIN: for my $i (0 .. $#$bins) { next BIN if $x >= $bins[$i]; $bucket_number = $i; last BIN; } die "$x too large to bucketize" unless defined $bucket_number; my $this_bucket = $bucket{ $bucket_number } ||= []; push @$this_bucket, $x; }; my $get_buckets = sub { %bucket }; return ($bucketizer, $get_buckets); } It would be pretty easy to adapt this code to not take ($n) as a power of ten, but to take (%buckets) as a map of max values to buckets or (@buckets) as a list of pairs. -- rjbs From faber at linuxnj.com Fri Oct 26 16:45:06 2007 From: faber at linuxnj.com (Faber J. Fedor) Date: Fri, 26 Oct 2007 19:45:06 -0400 Subject: [ABE.pm] My first enclosure doesn't work. :-( In-Reply-To: <20071026221307.GA6101@knight> References: <20071026173050.GA30227@neptune.faber.nom> <20071026221307.GA6101@knight> Message-ID: <20071026234506.GB31935@neptune.faber.nom> On 26/10/07 18:13 -0400, Ricardo SIGNES wrote: > * "Faber J. Fedor" [2007-10-26T13:30:50] > > Now what? At the end of my enclosure, I say 'return sub { $stmt };' or > > 'return sub { eval($stmt) };'. If I then do a 'print > > make_if_elsif(300)' I get 'CODE(0x8096228)' instead of the expected > > '1.0'. > > > > What am I doing wrong? > > Well, for one thing, you're even considering using string eval. :) But you guys use it all the time! > This code does *not* dynamically generate an if/else tree. Basically, in > dynamic Perl, you Just Don't Do That. if/else trees are literal structures, > and you'd have to generate code and then eval it. That's what I was trying to do. I wanted a function to write a function as mentioned in the first paragraph on Chapter 7 of HOP. > This is a red flag the size of Texas. Can you explain the concept of "code writing code" or "programs writing programs" then cuz I'm WAY off base. > Instead, you'd build a data structure that can serve as a kind of > dispatch table, I started down that route and ended up with the two-liner that I showed Walt. I'll look over your code and see what I can grok cuz I'm still trying to write my first practical closure. For the record, I didn't write the original if-elsif, but I am refactoring it out of the production code. -- Regards, Faber Fedor President Linux New Jersey, Inc. 908-320-0357 800-706-0701 http://www.linuxnj.com -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. From rjbs-perl-abe at lists.manxome.org Sat Oct 27 05:53:21 2007 From: rjbs-perl-abe at lists.manxome.org (Ricardo SIGNES) Date: Sat, 27 Oct 2007 08:53:21 -0400 Subject: [ABE.pm] My first enclosure doesn't work. :-( In-Reply-To: <20071026234506.GB31935@neptune.faber.nom> References: <20071026173050.GA30227@neptune.faber.nom> <20071026221307.GA6101@knight> <20071026234506.GB31935@neptune.faber.nom> Message-ID: <20071027125321.GA461@knight.cable.rcn.com> * "Faber J. Fedor" [2007-10-26T19:45:06] > > Well, for one thing, you're even considering using string eval. :) > > But you guys use it all the time! !?!? Who are you talking about?! I use string eval for exactly one use case, excepting REALLY weird exceptions: eval "require $module; 1"; In fact, I wrote a module that scans code to make sure it doesn't contain any string eval uses other than that. Do not confuse these two things: eval "if ($var) { do_something }"; eval { if ($var) { do_something } }; They are WILDLY different. The first one accepts a string and tries to use it like Perl code. The second one runs the included code, which was compiled along with everything else, and just catches exceptions. The first one is for use in case of REALLY REALLY weird needs. The second is for use ALL THE TIME. > > This code does *not* dynamically generate an if/else tree. Basically, in > > dynamic Perl, you Just Don't Do That. if/else trees are literal structures, > > and you'd have to generate code and then eval it. > > That's what I was trying to do. I wanted a function to write a function > as mentioned in the first paragraph on Chapter 7 of HOP. As far as I know, string eval is not used for any of the techniques in HOP. > > This is a red flag the size of Texas. > > Can you explain the concept of "code writing code" or "programs writing > programs" then cuz I'm WAY off base. You could use the phrase "code writing code" to mean "code that builds a string and then turns it into a sub," I suppose, but it's not what's really meant. It's about further and further refining what you need to write by building tools that convert your input data into code. Example: sub make_notifier { my ($frequency, $from, $to) = @_; my $last_sent = 0; sub { return unless time - $last_sent > $frequency; send_email( build_an_email, $to, $from, ); $last_sent = $frequency; }; } ...then elsewhere... my $notifier = make_notifier(3600, 'root at example.com', 'faber at example.com'); Now you have code ($notifier) written by code ($make_notifier) that sends a message to X from Y only if it has been at least Z seconds since the last time it did this. Maybe your program that uses this always uses similar settings, so you write: sub make_std_notifier { make_nofifier(3600, 'root at example.com', shift) } So make_std_notifier also builds code, but with a smaller range of customizaiton. my @notifiers = map { make_std_notifier($_) } @admins; A more complex, but possibly understandable example can be find in these modules: http://search.cpan.org/src/RJBS/String-Truncate-0.102/lib/String/Truncate.pm http://search.cpan.org/src/RJBS/Number-Nary-0.102/lib/Number/Nary.pm -- rjbs