From faber at linuxnj.com Mon Aug 4 11:17:38 2008 From: faber at linuxnj.com (Faber J. Fedor) Date: Mon, 4 Aug 2008 14:17:38 -0400 Subject: [ABE.pm] Agenda/Location? Message-ID: <20080804181738.GB18443@neptune.faber.nom> What's the agenda and location for this week's meetup? -- Regards, Faber Fedor President Linux New Jersey, Inc. 908-320-0357 800-706-0701 http://www.linuxnj.com From faber at linuxnj.com Mon Aug 4 11:32:30 2008 From: faber at linuxnj.com (Faber J. Fedor) Date: Mon, 4 Aug 2008 14:32:30 -0400 Subject: [ABE.pm] Agenda/Location? In-Reply-To: <20080804181738.GB18443@neptune.faber.nom> References: <20080804181738.GB18443@neptune.faber.nom> Message-ID: <20080804183230.GB18525@neptune.faber.nom> On 04/08/08 14:17 -0400, Faber J. Fedor wrote: > > What's the agenda and location for this week's meetup? Never mind, I just saw Rick's email. (Why is mutt not recognizing updated mailboxes? Hmm...) -- Regards, Faber Fedor President Linux New Jersey, Inc. 908-320-0357 800-706-0701 http://www.linuxnj.com From perl.abe at rjbs.manxome.org Mon Aug 4 12:09:33 2008 From: perl.abe at rjbs.manxome.org (Ricardo SIGNES) Date: Mon, 4 Aug 2008 15:09:33 -0400 Subject: [ABE.pm] another reminder, just because Message-ID: <20080804190933.GA7326@cancer.codesimply.com> 18:00. McGrady's. Wednesday. -- rjbs From fiedlert at gmail.com Tue Aug 5 17:28:51 2008 From: fiedlert at gmail.com (Ted Fiedler) Date: Tue, 5 Aug 2008 20:28:51 -0400 Subject: [ABE.pm] another reminder, just because In-Reply-To: <20080804190933.GA7326@cancer.codesimply.com> References: <20080804190933.GA7326@cancer.codesimply.com> Message-ID: <814422ce0808051728s196e8334n6f00dedabf1c529a@mail.gmail.com> Im not going to be able to make it. For some reason the first Wednesday of each month seems to always be a bad day for me... On Mon, Aug 4, 2008 at 3:09 PM, Ricardo SIGNES wrote: > > 18:00. McGrady's. Wednesday. > > -- > rjbs > _______________________________________________ > ABE-pm mailing list > ABE-pm at pm.org > http://mail.pm.org/mailman/listinfo/abe-pm > -- We do these things not because they are easy, but because they are hard - John F. Kennedy From perl.abe at rjbs.manxome.org Tue Aug 5 18:13:06 2008 From: perl.abe at rjbs.manxome.org (Ricardo SIGNES) Date: Tue, 5 Aug 2008 21:13:06 -0400 Subject: [ABE.pm] another reminder, just because In-Reply-To: <814422ce0808051728s196e8334n6f00dedabf1c529a@mail.gmail.com> References: <20080804190933.GA7326@cancer.codesimply.com> <814422ce0808051728s196e8334n6f00dedabf1c529a@mail.gmail.com> Message-ID: <20080806011306.GA12722@cancer.codesimply.com> * Ted Fiedler [2008-08-05T20:28:51] > Im not going to be able to make it. For some reason the first > Wednesday of each month seems to always be a bad day for me... Tom is on vacation down the shore... so neither of the TFs. Faber, you'll be there? Paul? Anybody else? -- rjbs From faber at linuxnj.com Tue Aug 5 19:33:00 2008 From: faber at linuxnj.com (Faber J. Fedor) Date: Tue, 5 Aug 2008 22:33:00 -0400 Subject: [ABE.pm] another reminder, just because In-Reply-To: <20080806011306.GA12722@cancer.codesimply.com> References: <20080804190933.GA7326@cancer.codesimply.com> <814422ce0808051728s196e8334n6f00dedabf1c529a@mail.gmail.com> <20080806011306.GA12722@cancer.codesimply.com> Message-ID: <20080806023300.GA30608@neptune.faber.nom> On 05/08/08 21:13 -0400, Ricardo SIGNES wrote: > * Ted Fiedler [2008-08-05T20:28:51] > > Im not going to be able to make it. For some reason the first > > Wednesday of each month seems to always be a bad day for me... > > Tom is on vacation down the shore... so neither of the TFs. Faber, you'll be > there? Paul? Anybody else? Yeah, we'll be there. Paul and I will be coding (in @#^%^ PHP) at the Wired coffee shop on Main street starting at ~3PM, then we'll mosey on down to McG's around 5:30 or so. Looks like we should start a membership drive! -- Regards, Faber Fedor President Linux New Jersey, Inc. 908-320-0357 800-706-0701 http://www.linuxnj.com From perl.abe at rjbs.manxome.org Tue Aug 5 19:34:59 2008 From: perl.abe at rjbs.manxome.org (Ricardo SIGNES) Date: Tue, 5 Aug 2008 22:34:59 -0400 Subject: [ABE.pm] another reminder, just because In-Reply-To: <20080806023300.GA30608@neptune.faber.nom> References: <20080804190933.GA7326@cancer.codesimply.com> <814422ce0808051728s196e8334n6f00dedabf1c529a@mail.gmail.com> <20080806011306.GA12722@cancer.codesimply.com> <20080806023300.GA30608@neptune.faber.nom> Message-ID: <20080806023459.GA13056@cancer.codesimply.com> * "Faber J. Fedor" [2008-08-05T22:33:00] > On 05/08/08 21:13 -0400, Ricardo SIGNES wrote: > > * Ted Fiedler [2008-08-05T20:28:51] > > > Im not going to be able to make it. For some reason the first > > > Wednesday of each month seems to always be a bad day for me... > > > > Tom is on vacation down the shore... so neither of the TFs. Faber, you'll > > be there? Paul? Anybody else? > > Yeah, we'll be there. Paul and I will be coding (in @#^%^ PHP) at the Wired > coffee shop on Main street starting at ~3PM, then we'll mosey on down to > McG's around 5:30 or so. Maybe I should walk past there and meet up with you on the way. It's only a few blocks out of my way. Of course, it does mean braving Musikfest! > Looks like we should start a membership drive! I've just been wondering about how to find fresh meat, on my journal. I almost wonder whether the intensely boring (well, business-minded) LV .NET user group has any prospective hangers out. -- rjbs From faber at linuxnj.com Tue Aug 5 19:43:49 2008 From: faber at linuxnj.com (Faber J. Fedor) Date: Tue, 5 Aug 2008 22:43:49 -0400 Subject: [ABE.pm] Ignore this email Message-ID: <20080806024349.GA30660@neptune.faber.nom> I'm testing to see if mutt will pick up on any new email in the abe-pm folder. -- Regards, Faber Fedor President Linux New Jersey, Inc. 908-320-0357 800-706-0701 http://www.linuxnj.com From faber at linuxnj.com Tue Aug 5 19:59:58 2008 From: faber at linuxnj.com (Faber J. Fedor) Date: Tue, 5 Aug 2008 22:59:58 -0400 Subject: [ABE.pm] another reminder, just because In-Reply-To: <20080806023459.GA13056@cancer.codesimply.com> References: <20080804190933.GA7326@cancer.codesimply.com> <814422ce0808051728s196e8334n6f00dedabf1c529a@mail.gmail.com> <20080806011306.GA12722@cancer.codesimply.com> <20080806023300.GA30608@neptune.faber.nom> <20080806023459.GA13056@cancer.codesimply.com> Message-ID: <20080806025958.GB30660@neptune.faber.nom> On 05/08/08 22:34 -0400, Ricardo SIGNES wrote: > Maybe I should walk past there and meet up with you on the way. It's only a > few blocks out of my way. > > Of course, it does mean braving Musikfest! Wait, what? I thought that was a weekend thing! FRAK! I *hate* crowds! > > Looks like we should start a membership drive! > > I've just been wondering about how to find fresh meat, on my journal. I almost > wonder whether the intensely boring (well, business-minded) LV .NET user group > has any prospective hangers out. Maybe we (meaning you) should extol the virtues of Perl to other local groups, like the .NET ppl. -- Regards, Faber Fedor President Linux New Jersey, Inc. 908-320-0357 800-706-0701 http://www.linuxnj.com From faber at linuxnj.com Tue Aug 5 20:01:29 2008 From: faber at linuxnj.com (Faber J. Fedor) Date: Tue, 5 Aug 2008 23:01:29 -0400 Subject: [ABE.pm] Ignore this email In-Reply-To: <20080806024349.GA30660@neptune.faber.nom> References: <20080806024349.GA30660@neptune.faber.nom> Message-ID: <20080806030129.GC30660@neptune.faber.nom> On 05/08/08 22:43 -0400, Faber J. Fedor wrote: > I'm testing to see if mutt will pick up on any new email in the abe-pm > folder. It useta' work! Why doesn't it any more? -- Regards, Faber Fedor President Linux New Jersey, Inc. 908-320-0357 800-706-0701 http://www.linuxnj.com From faber at linuxnj.com Fri Aug 8 10:04:49 2008 From: faber at linuxnj.com (Faber J. Fedor) Date: Fri, 8 Aug 2008 13:04:49 -0400 Subject: [ABE.pm] closure question Message-ID: <20080808170449.GA3351@neptune.faber.nom> Take your canonical closure example: sub plusplus { my $n = shift; return sub { $n++ ;} } my $seed = 1; my $c = plusplus($seed); print $c->()."\n"; print $c->()."\n"; $seed = 100; my $d = plusplus($seed); print $d->()."\n"; print $d->()."\n"; The output of which is, naturally, 1 2 100 101 I understand the 2 and the 101. I don't understand the 1 and the 100. Why does the first call to the closure result in $seed and not $seed++? -- Regards, Faber Fedor President Linux New Jersey, Inc. 908-320-0357 800-706-0701 http://www.linuxnj.com From andy at hexten.net Fri Aug 8 10:07:17 2008 From: andy at hexten.net (Andy Armstrong) Date: Fri, 8 Aug 2008 18:07:17 +0100 Subject: [ABE.pm] closure question In-Reply-To: <20080808170449.GA3351@neptune.faber.nom> References: <20080808170449.GA3351@neptune.faber.nom> Message-ID: <4BB9FBCF-6769-49E0-8F2E-A67EC017838F@hexten.net> On 8 Aug 2008, at 18:04, Faber J. Fedor wrote: > Take your canonical closure example: > > sub plusplus { > my $n = shift; > return sub { $n++ ;} > } > > my $seed = 1; > my $c = plusplus($seed); > > print $c->()."\n"; > print $c->()."\n"; > > $seed = 100; > my $d = plusplus($seed); > print $d->()."\n"; > print $d->()."\n"; > > The output of which is, naturally, > > 1 > 2 > 100 > 101 > > > I understand the 2 and the 101. I don't understand the 1 and the 100. > Why does the first call to the closure result in $seed and not $seed+ > +? $seed++ is $seed - ++ after the scalar is a postincrement - it returns the current value then increments it. If you want preincrement do ++ $seed instead. -- Andy Armstrong, Hexten From faber at linuxnj.com Fri Aug 8 10:13:02 2008 From: faber at linuxnj.com (Faber J. Fedor) Date: Fri, 8 Aug 2008 13:13:02 -0400 Subject: [ABE.pm] closure question In-Reply-To: <4BB9FBCF-6769-49E0-8F2E-A67EC017838F@hexten.net> References: <20080808170449.GA3351@neptune.faber.nom> <4BB9FBCF-6769-49E0-8F2E-A67EC017838F@hexten.net> Message-ID: <20080808171302.GB3351@neptune.faber.nom> On 08/08/08 18:07 +0100, Andy Armstrong wrote: > $seed++ is $seed - ++ after the scalar is a postincrement - it returns > the current value then increments it. If you want preincrement do ++ > $seed instead. I knew I was missing something obvious. Thanks. -- Regards, Faber Fedor President Linux New Jersey, Inc. 908-320-0357 800-706-0701 http://www.linuxnj.com From andy at hexten.net Fri Aug 8 10:15:27 2008 From: andy at hexten.net (Andy Armstrong) Date: Fri, 8 Aug 2008 18:15:27 +0100 Subject: [ABE.pm] closure question In-Reply-To: <20080808171302.GB3351@neptune.faber.nom> References: <20080808170449.GA3351@neptune.faber.nom> <4BB9FBCF-6769-49E0-8F2E-A67EC017838F@hexten.net> <20080808171302.GB3351@neptune.faber.nom> Message-ID: <298EC091-BFC2-41F6-8E61-444360370435@hexten.net> On 8 Aug 2008, at 18:13, Faber J. Fedor wrote: > On 08/08/08 18:07 +0100, Andy Armstrong wrote: >> $seed++ is $seed - ++ after the scalar is a postincrement - it >> returns >> the current value then increments it. If you want preincrement do ++ >> $seed instead. > > I knew I was missing something obvious. Thanks. I /will/ get to one of the meetings... One day :) -- Andy Armstrong, Hexten From faber at linuxnj.com Fri Aug 8 10:57:52 2008 From: faber at linuxnj.com (Faber J. Fedor) Date: Fri, 8 Aug 2008 13:57:52 -0400 Subject: [ABE.pm] non-trivial closure examples? Message-ID: <20080808175752.GA3893@neptune.faber.nom> Does anyone know of any? I'm teaching a Perl class to Java programmers in a coupla' weeks and I'm looking for some fun stuff to throw in to show them that Perl is a Real Language. I've got the canonical example of a closure, now I'm looking for something that is useful but doesn't require explaining a whole lot of other functionality to understand what the closure is doing, e.g. Memoize would not be a good example since I would have to explain everything Memoize is trying to accomplish.. -- Regards, Faber Fedor President Linux New Jersey, Inc. 908-320-0357 800-706-0701 http://www.linuxnj.com From hdp at pobox.com Fri Aug 8 11:06:41 2008 From: hdp at pobox.com (Hans Dieter Pearcey) Date: Fri, 8 Aug 2008 14:06:41 -0400 Subject: [ABE.pm] non-trivial closure examples? In-Reply-To: <20080808175752.GA3893@neptune.faber.nom> References: <20080808175752.GA3893@neptune.faber.nom> Message-ID: <20080808180640.GW15550@glaive.weftsoar.net> On Fri, Aug 08, 2008 at 01:57:52PM -0400, Faber J. Fedor wrote: > Does anyone know of any? http://search.cpan.org/~petdance/File-Next-1.02/Next.pm dir_walk (or many other examples) in Higher Order Perl hdp. From perl.abe at rjbs.manxome.org Fri Aug 8 12:52:03 2008 From: perl.abe at rjbs.manxome.org (Ricardo SIGNES) Date: Fri, 8 Aug 2008 15:52:03 -0400 Subject: [ABE.pm] non-trivial closure examples? In-Reply-To: <20080808175752.GA3893@neptune.faber.nom> References: <20080808175752.GA3893@neptune.faber.nom> Message-ID: <20080808195203.GA2938@cancer.codesimply.com> * "Faber J. Fedor" [2008-08-08T13:57:52] > I've got the canonical example of a closure, now I'm looking for Make sure you explain closures first. Java doesn't have them. > Memoize would not be a good example since I would have to explain > everything Memoize is trying to accomplish.. Memoize is a pretty good example. All you have to explain is how it makes fibbonacci faster. -- rjbs From faber at linuxnj.com Fri Aug 8 14:47:55 2008 From: faber at linuxnj.com (Faber J. Fedor) Date: Fri, 8 Aug 2008 17:47:55 -0400 Subject: [ABE.pm] non-trivial closure examples? In-Reply-To: <20080808195203.GA2938@cancer.codesimply.com> References: <20080808175752.GA3893@neptune.faber.nom> <20080808195203.GA2938@cancer.codesimply.com> Message-ID: <20080808214755.GB4435@neptune.faber.nom> On 08/08/08 15:52 -0400, Ricardo SIGNES wrote: > * "Faber J. Fedor" [2008-08-08T13:57:52] > > I've got the canonical example of a closure, now I'm looking for > > Make sure you explain closures first. Java doesn't have them. Really? I was under the impression they could do them but the syntax is horrible. Unfortunately, I can't find the reference right now. > > Memoize would not be a good example since I would have to explain > > everything Memoize is trying to accomplish.. > > Memoize is a pretty good example. All you have to explain is how it makes > fibbonacci faster. I'm sure that's high on their to-do list. :-) -- Regards, Faber Fedor President Linux New Jersey, Inc. 908-320-0357 800-706-0701 http://www.linuxnj.com From perl.abe at rjbs.manxome.org Fri Aug 8 15:02:47 2008 From: perl.abe at rjbs.manxome.org (Ricardo SIGNES) Date: Fri, 8 Aug 2008 18:02:47 -0400 Subject: [ABE.pm] non-trivial closure examples? In-Reply-To: <20080808214755.GB4435@neptune.faber.nom> References: <20080808175752.GA3893@neptune.faber.nom> <20080808195203.GA2938@cancer.codesimply.com> <20080808214755.GB4435@neptune.faber.nom> Message-ID: <20080808220247.GB3381@cancer.codesimply.com> * "Faber J. Fedor" [2008-08-08T17:47:55] > On 08/08/08 15:52 -0400, Ricardo SIGNES wrote: > > * "Faber J. Fedor" [2008-08-08T13:57:52] > > > I've got the canonical example of a closure, now I'm looking for > > > > Make sure you explain closures first. Java doesn't have them. > > Really? I was under the impression they could do them but the syntax is > horrible. Unfortunately, I can't find the reference right now. Nope. http://www.google.com/search?ie=utf8&oe=utf8&q=java%20closure They don't really need them, because... http://www.kimbly.com/blog/000063.html > > > Memoize would not be a good example since I would have to explain > > > everything Memoize is trying to accomplish.. > > > > Memoize is a pretty good example. All you have to explain is how it makes > > fibbonacci faster. > > I'm sure that's high on their to-do list. :-) Sure, but any competent programmer will be able to go from that application to understanding others. Alternately, avoid fibb, since it brings recursion to the table. Instead, you can use it for some other expensive operation, like parsing the contents of an XML file into an immutable tree, or computing the primality of a number. That example has the benefit of being useful either recursively or not. -- rjbs From rhkramer at gmail.com Mon Aug 11 06:01:16 2008 From: rhkramer at gmail.com (Randy Kramer) Date: Mon, 11 Aug 2008 09:01:16 -0400 Subject: [ABE.pm] Fwd: [ANN] 7th batch - Free Ruby Programming Course Message-ID: <200808110901.18431.rhkramer@gmail.com> I just found this and signed up for it. I suspect it's going to be on the elementary side, but there may be others who are interested. I think I'm a little beyond the newbie stage when I stay close enough to ruby to remember what I've learned. Hopefully (I know), this will help me fix some of the things I've already learned in memory, and maybe I'll learn some new stuff. IIUC, there are advanced courses (that may not be free) "coming down the pike, including one on (Ruby on) Rails. Randy Kramer BTW, the instructor (Satish Talim) is an Indian from India, but I don't think I'll have nearly the trouble I had in school and work with his (presumed) Indian accent. ;-) (Although I've also dealt with written German, Austrian, French, Japanese and even British "English" and know that they each have their ideosyncracies--hmm, I've even dealt with Indian English before--I can't recall any problems with that--maybe I have a selective memory.) Seriously, though, so far everything I've seen on the site (from Satish) seems to be well-written English. ---------- Forwarded Message ---------- Subject: [ANN] 7th batch - Free Ruby Programming Course Date: Sunday 10 August 2008 09:01 pm From: "Satish Talim" To: "ruby-talk ML" The 7th batch of the Free Online Ruby Programming Course begins on *Saturday, 6th Sept. 2008. Enrollments have started and the course syllabus, registration details etc are available here - http://rubylearning.com/blog/2008/08/04/announcing-the-7th-free-ruby-programming-batch/ Satish * ------------------------------------------------------- From perl.abe at rjbs.manxome.org Mon Aug 11 09:50:23 2008 From: perl.abe at rjbs.manxome.org (Ricardo SIGNES) Date: Mon, 11 Aug 2008 12:50:23 -0400 Subject: [ABE.pm] php and me Message-ID: <20080811165023.GA11541@cancer.codesimply.com> I am porting Rx to PHP as part of my "make Rx run everywhere" campaign. Oh, how PHP makes me crazy! Here is the spin of the century: The array type in PHP is very versatile. I particularly like it in reference to: // This array is the same as ... array(5 => 43, 32, 56, "b" => 12); // ...this array // array(5 => 43, 6 => 32, 7 => 56, "b" => 12); Oof! I also found this gem while looking up return. Note: Note that since return() is a language construct and not a function, the parentheses surrounding its arguments are not required. It is common to leave them out, and you actually should do so as PHP has less work to do in this case. So, first of all, you want me to optimize for the language? Really? Isn't it there to make my life easier? Well, that's not the only reason: Note: You should never use parentheses around your return variable when returning by reference, as this will not work. You can only return variables by reference, not the result of a statement. If you use return ($a); then you're not returning a variable, but the result of the expression ($a) (which is, of course, the value of $a). Yow. Then there's http://www.php.net/quickref.php Anyway, maybe I shouldn't act like such a language basher, since I'm probably going to ask some stupid PHP questions over the next day or two. Mostly about objects and arrays. I knew that arrays had multiple-personality disorder, but it seems even wackier than I thought. I have a sinking feeling that validing that something is a sequence (which means something like "an ordered list of values") or a record (which is something like "a group of named values") is going to be hard to get just right. I think I will need to allow arrays for both and also stdClass objects for records. I really like the library-building culture of the other dynamic languages. The language stays small and is thus easy to learn. PHP isn't without libraries, especially now that there are tolerable classes, but... oof. I wish they'd gone that way much earlier. -- rjbs From faber at linuxnj.com Mon Aug 11 10:03:14 2008 From: faber at linuxnj.com (Faber J. Fedor) Date: Mon, 11 Aug 2008 13:03:14 -0400 Subject: [ABE.pm] php and me In-Reply-To: <20080811165023.GA11541@cancer.codesimply.com> References: <20080811165023.GA11541@cancer.codesimply.com> Message-ID: <20080811170314.GD26245@neptune.faber.nom> On 11/08/08 12:50 -0400, Ricardo SIGNES wrote: > > I am porting Rx to PHP as part of my "make Rx run everywhere" campaign. > > Oh, how PHP makes me crazy! Here is the spin of the century: My favorite thing I read was something along the lines of "constants have one major disadvantage: you can't change their value once they're set". DUH! > I really like the library-building culture of the other dynamic languages. > The language stays small and is thus easy to learn. PHP isn't without > libraries, especially now that there are tolerable classes, but... oof. I wish > they'd gone that way much earlier. I get the feeling the language designers at PHP know as much about designing a language as I do, IOW, not much. -- Regards, Faber Fedor President Linux New Jersey, Inc. 908-320-0357 800-706-0701 http://www.linuxnj.com From andy at hexten.net Mon Aug 11 10:09:57 2008 From: andy at hexten.net (Andy Armstrong) Date: Mon, 11 Aug 2008 18:09:57 +0100 Subject: [ABE.pm] php and me In-Reply-To: <20080811165023.GA11541@cancer.codesimply.com> References: <20080811165023.GA11541@cancer.codesimply.com> Message-ID: <73F0741F-529E-474C-8030-775E3C4178DE@hexten.net> On 11 Aug 2008, at 17:50, Ricardo SIGNES wrote: > I knew that arrays had multiple-personality disorder, but it seems > even wackier > than I thought. I have a sinking feeling that validing that > something is a > sequence (which means something like "an ordered list of values") or > a record > (which is something like "a group of named values") is going to be > hard to get > just right. I think I will need to allow arrays for both and also > stdClass > objects for records. As far as I know all you can do is assume that if the subscripts are all integers, start at zero and there are no gaps in the numbering that it's an array. In particular you'll be pleased to note that an empty array IS an empty hash - there is no way they can be distinguished because they're the same thing. PHP's own JSON encoder treats empty things as arrays rather than hashes: print json_encode(array()); [] Fun :) -- Andy Armstrong, Hexten From perl.abe at rjbs.manxome.org Mon Aug 11 11:20:30 2008 From: perl.abe at rjbs.manxome.org (Ricardo SIGNES) Date: Mon, 11 Aug 2008 14:20:30 -0400 Subject: [ABE.pm] php and me In-Reply-To: <73F0741F-529E-474C-8030-775E3C4178DE@hexten.net> References: <20080811165023.GA11541@cancer.codesimply.com> <73F0741F-529E-474C-8030-775E3C4178DE@hexten.net> Message-ID: <20080811182030.GA15216@cancer.codesimply.com> * Andy Armstrong [2008-08-11T13:09:57] > As far as I know all you can do is assume that if the subscripts are > all integers, start at zero and there are no gaps in the numbering > that it's an array. In particular you'll be pleased to note that an > empty array IS an empty hash - there is no way they can be > distinguished because they're the same thing. > > PHP's own JSON encoder treats empty things as arrays rather than hashes: > > print json_encode(array()); > [] Ha. So, solution: arrays must have 0 or more sequential integer keys. Records and maps must be stdClass objects. -- rjbs From perl.abe at rjbs.manxome.org Mon Aug 11 17:52:29 2008 From: perl.abe at rjbs.manxome.org (Ricardo SIGNES) Date: Mon, 11 Aug 2008 20:52:29 -0400 Subject: [ABE.pm] php 1, rjbs 0 Message-ID: <20080812005229.GA16732@cancer.codesimply.com> So, I have filed my first PHP bug of this PHP-writing campaign. A few years ago, when JSON was starting to become really popular, someone wrote a PHP library for dealing with JSON. Great! Now if your program needs to deal with JSON, you load the extension and off you go! JSON got more popular, though, and everybody liked the library, so PHP did what PHP does: it made it part of core PHP. Now you didn't need to require the library. You just got json_encode and json_decode for free. There are some bugs, though. Here's a humdinger: { "zero": 0e0 } That's totally valid JSON, and the value for the "zero" property is numerically zero. PHP loads that as ($obj->zero = NULL). Oops! Well, in a library-loving culture, that's no problem. You'd just download the latest version of the JSON library and upgrade that. Done! You can't do that anymore, though, because now JSON support is in the core and nowhere else. You'll have to wait for the next version of PHP. Of course, when you upgrade *that*, who knows what other things have changed. You're getting one gigantic upgrade that might break other parts of your code. "I can't get a JSON bug fix because it would break a MySQL behavior we rely on. No, no, they're not related." In Perl, most libraries are not in the core. They live on the CPAN, so you can upgrade them in isolation. Even those that *are* in the core are still libraries, not part of the syntax of the language. Many of those are *also* on the CPAN, and there are upgraded versions distributed that won't require upgrading Perl. (These are called "dual-lived" modules.) Finally, even if you had to change the behavior of a really internal bit of Perl, you can. You can make functions that replace built-ins, either locally or globally. In PHP, if you try to make a function called "json_decode," your program fails. Oh well. This means my tests for the datapoint num/0e0 fail. I think I'll move on to the range checks. Time to pretend PHP has closures... -- rjbs From perl.abe at rjbs.manxome.org Mon Aug 11 18:29:47 2008 From: perl.abe at rjbs.manxome.org (Ricardo SIGNES) Date: Mon, 11 Aug 2008 21:29:47 -0400 Subject: [ABE.pm] work with rjbs! two junior positions open Message-ID: <20080812012947.GB16924@cancer.codesimply.com> I'm really hoping to find some cool, eager junior types to come work at Pobox. Normally I wouldn't post a job opening here, but I think we've got some cool work coming up, so I'm being brazen. http://philadelphia.craigslist.org/sad/792369480.html http://philadelphia.craigslist.org/eng/792365652.html -- rjbs From faber at linuxnj.com Tue Aug 12 15:13:35 2008 From: faber at linuxnj.com (Faber J. Fedor) Date: Tue, 12 Aug 2008 18:13:35 -0400 Subject: [ABE.pm] curriculum ideas Message-ID: <20080812221335.GB7878@neptune.faber.nom> For the past two weeks, I've been prepping to teach a four-day class on Perl to Java programmers who know nothing about Perl, concentrating on OOP Perl. I figured most of my time would be spent going over the differences between the two language and then concentrating on writing objects. I find out today they're not "Java programmers who know nothing of Perl". They run the gamut from having had to trouble-shoot a Perl script to people who code in Perl everyday (described as "heavy hitters")! They're main interest is in getting better at Perl and being able to support Movable Type for which the have plugins written by consultants that need support. Class starts on Monday. The curriculum I have, with this group, I can cover in two days. Three if I talk rrrreeeaaallll ssssssllllllllloooooooowwwwwww. But, you know I can't talk slow. So I'm looking for ideas on what to do with these guys. I'm looking for interesting ideas to go over and/or hack together. I'm going to pour over HOP and "Advanced Perl Programming" for ideas. A few things I've already come up with are complex data structures (AoA, HoH, etc.), caching of data, and some more complicated examples of closures. Have them debug a Perl script that's *really* tricky/buggy ? Suggestions and prayers welcome. -- Regards, Faber Fedor President Linux New Jersey, Inc. 908-320-0357 800-706-0701 http://www.linuxnj.com From perl.abe at rjbs.manxome.org Tue Aug 12 15:31:03 2008 From: perl.abe at rjbs.manxome.org (Ricardo SIGNES) Date: Tue, 12 Aug 2008 18:31:03 -0400 Subject: [ABE.pm] curriculum ideas In-Reply-To: <20080812221335.GB7878@neptune.faber.nom> References: <20080812221335.GB7878@neptune.faber.nom> Message-ID: <20080812223103.GA21896@cancer.codesimply.com> * "Faber J. Fedor" [2008-08-12T18:13:35] > So I'm looking for ideas on what to do with these guys. I'm looking for > interesting ideas to go over and/or hack together. I'm going > to pour over HOP and "Advanced Perl Programming" for ideas. A few > things I've already come up with are complex data structures (AoA, HoH, > etc.), caching of data, and some more complicated examples of closures. > Have them debug a Perl script that's *really* tricky/buggy ? Moose. mro.pm Inside-out objects. Hash::Util::FieldHash. overload.pm Class::Classless. Smartmatching, ~~ overloading, and Smartmatch::Sugar. Design patterns. Java programmers LOVE design patterns. http://perldesignpatterns.com/?PerlDesignPatterns Exception objects with Exception::Class. Cycles, ref weakening, and cycle/loop detectors. Test::Class. (Tell them "it's like jUnit.") -- rjbs From faber at linuxnj.com Tue Aug 12 15:59:38 2008 From: faber at linuxnj.com (Faber J. Fedor) Date: Tue, 12 Aug 2008 18:59:38 -0400 Subject: [ABE.pm] curriculum ideas In-Reply-To: <20080812223103.GA21896@cancer.codesimply.com> References: <20080812221335.GB7878@neptune.faber.nom> <20080812223103.GA21896@cancer.codesimply.com> Message-ID: <20080812225938.GA8030@neptune.faber.nom> On 12/08/08 18:31 -0400, Ricardo SIGNES wrote: > * "Faber J. Fedor" [2008-08-12T18:13:35] > > So I'm looking for ideas on what to do with these guys. I'm looking for > > interesting ideas to go over and/or hack together. I'm going > > to pour over HOP and "Advanced Perl Programming" for ideas. A few > > things I've already come up with are complex data structures (AoA, HoH, > > etc.), caching of data, and some more complicated examples of closures. > > Have them debug a Perl script that's *really* tricky/buggy ? > > Moose. mro.pm > > Inside-out objects. Hash::Util::FieldHash. overload.pm I guess I should have added the restriction "and things that *I* understand". :-) A couple of those I've never heard of, some like Moose, I don't think I could learn in time, a couple of the others will come in handy. More! More! -- Regards, Faber Fedor President Linux New Jersey, Inc. 908-320-0357 800-706-0701 http://www.linuxnj.com From perl.abe at rjbs.manxome.org Tue Aug 12 17:45:30 2008 From: perl.abe at rjbs.manxome.org (Ricardo SIGNES) Date: Tue, 12 Aug 2008 20:45:30 -0400 Subject: [ABE.pm] first legitimate PHP question Message-ID: <20080813004530.GA22408@cancer.codesimply.com> I have some code roughly in this form: try { print "about to try\n"; $x = y(); print "done trying\n"; } catch (Exception $e) { print "caught exception\n"; } I see "about to try" but not "done trying" and this happens: Catchable fatal error: Object of class stdClass could not be converted to string in /Users/rjbs/code/projects/Rx/php/Rx.php on line 54 Why isn't that exception getting caught? This code is in git://git.codesimply.com/Rx -- rjbs From aferreira at shopzilla.com Tue Aug 12 18:02:22 2008 From: aferreira at shopzilla.com (Adriano Ferreira) Date: Tue, 12 Aug 2008 22:02:22 -0300 Subject: [ABE.pm] first legitimate PHP question In-Reply-To: <20080813004530.GA22408@cancer.codesimply.com> References: <20080813004530.GA22408@cancer.codesimply.com> Message-ID: <73ddeb6c0808121802m148e0222j204b19e0c195f5f5@mail.gmail.com> On Tue, Aug 12, 2008 at 9:45 PM, Ricardo SIGNES wrote: > > I have some code roughly in this form: > > try { > print "about to try\n"; > $x = y(); > print "done trying\n"; > } catch (Exception $e) { > print "caught exception\n"; > } > > I see "about to try" but not "done trying" and this happens: > > Catchable fatal error: Object of class stdClass could not be converted to > string in /Users/rjbs/code/projects/Rx/php/Rx.php on line 54 A wild guess: if the PHP developers worked their exception model based on Java, it may be that this "catchable error" is a more generic thing than an exception, like Java Throwable, and then maybe you should use } catch (Throwable $e) { print "caught exception\n"; } to get this too. Otherwise, it understand you don't want to handle that here, and follows along. > Why isn't that exception getting caught? > > This code is in git://git.codesimply.com/Rx > > -- > rjbs > _______________________________________________ > ABE-pm mailing list > ABE-pm at pm.org > http://mail.pm.org/mailman/listinfo/abe-pm > From perl.abe at rjbs.manxome.org Tue Aug 12 18:17:13 2008 From: perl.abe at rjbs.manxome.org (Ricardo SIGNES) Date: Tue, 12 Aug 2008 21:17:13 -0400 Subject: [ABE.pm] first legitimate PHP question In-Reply-To: <73ddeb6c0808121802m148e0222j204b19e0c195f5f5@mail.gmail.com> References: <20080813004530.GA22408@cancer.codesimply.com> <73ddeb6c0808121802m148e0222j204b19e0c195f5f5@mail.gmail.com> Message-ID: <20080813011712.GA22543@cancer.codesimply.com> * Adriano Ferreira [2008-08-12T21:02:22] > On Tue, Aug 12, 2008 at 9:45 PM, Ricardo SIGNES > wrote: > > > > I have some code roughly in this form: > > > > try { > > print "about to try\n"; > > $x = y(); > > print "done trying\n"; > > } catch (Exception $e) { > > print "caught exception\n"; > > } Here is an actual failing piece of code: > A wild guess: if the PHP developers worked their exception model based > on Java, it may be that this "catchable error" is a more generic thing > than an exception, like Java Throwable, and then maybe you should use Sadly, nope. Thanks for the suggestion, though. I hate that it says "Catchable fatal error", because otherwise I'd surmise that I can't catch it. -- rjbs From perl.abe at rjbs.manxome.org Tue Aug 12 18:20:52 2008 From: perl.abe at rjbs.manxome.org (Ricardo SIGNES) Date: Tue, 12 Aug 2008 21:20:52 -0400 Subject: [ABE.pm] first legitimate PHP question In-Reply-To: <20080813011712.GA22543@cancer.codesimply.com> References: <20080813004530.GA22408@cancer.codesimply.com> <73ddeb6c0808121802m148e0222j204b19e0c195f5f5@mail.gmail.com> <20080813011712.GA22543@cancer.codesimply.com> Message-ID: <20080813012052.GB22543@cancer.codesimply.com> * Ricardo SIGNES [2008-08-12T21:17:13] > Sadly, nope. Thanks for the suggestion, though. > > I hate that it says "Catchable fatal error", because otherwise I'd surmise > that I can't catch it. Oh. My. Gosh. http://www.zend.com/forums/index.php?t=rview&th=2607&goto=6920 You can't catch catchable fatal errors. You must have a global error handler in place. -- rjbs From waltman at pobox.com Tue Aug 12 18:25:34 2008 From: waltman at pobox.com (Walt Mankowski) Date: Tue, 12 Aug 2008 21:25:34 -0400 Subject: [ABE.pm] first legitimate PHP question In-Reply-To: <20080813012052.GB22543@cancer.codesimply.com> References: <20080813004530.GA22408@cancer.codesimply.com> <73ddeb6c0808121802m148e0222j204b19e0c195f5f5@mail.gmail.com> <20080813011712.GA22543@cancer.codesimply.com> <20080813012052.GB22543@cancer.codesimply.com> Message-ID: <20080813012534.GQ7817@mawode.com> On Tue, Aug 12, 2008 at 09:20:52PM -0400, Ricardo SIGNES wrote: > You can't catch catchable fatal errors. You must have a global error handler > in place. That's an interesting use of the word "catchable"... Have they redefined any other English words that you know of? From perl.abe at rjbs.manxome.org Tue Aug 12 20:03:24 2008 From: perl.abe at rjbs.manxome.org (Ricardo SIGNES) Date: Tue, 12 Aug 2008 23:03:24 -0400 Subject: [ABE.pm] Rx.php passes all tests Message-ID: <20080813030324.GA22956@cancer.codesimply.com> Yeesh. At significant cost to my composure, Rx.php is now implemented! I expect you PHP programmers out there (you know who you are) to start using it asap! -- rjbs From andy at hexten.net Wed Aug 13 04:32:08 2008 From: andy at hexten.net (Andy Armstrong) Date: Wed, 13 Aug 2008 13:32:08 +0200 Subject: [ABE.pm] first legitimate PHP question In-Reply-To: <20080813012534.GQ7817@mawode.com> References: <20080813004530.GA22408@cancer.codesimply.com> <73ddeb6c0808121802m148e0222j204b19e0c195f5f5@mail.gmail.com> <20080813011712.GA22543@cancer.codesimply.com> <20080813012052.GB22543@cancer.codesimply.com> <20080813012534.GQ7817@mawode.com> Message-ID: <236CACEC-1F92-408B-A689-1F39BCDDFA80@hexten.net> On 13 Aug 2008, at 03:25, Walt Mankowski wrote: > On Tue, Aug 12, 2008 at 09:20:52PM -0400, Ricardo SIGNES wrote: >> You can't catch catchable fatal errors. You must have a global >> error handler >> in place. > > That's an interesting use of the word "catchable"... Have they > redefined any other English words that you know of? "programming" :) -- Andy Armstrong, Hexten From faber at linuxnj.com Wed Aug 13 12:18:59 2008 From: faber at linuxnj.com (Faber J. Fedor) Date: Wed, 13 Aug 2008 15:18:59 -0400 Subject: [ABE.pm] searching the archives Message-ID: <20080813191859.GA20782@neptune.faber.nom> How do I search the ML archives? I want to look up the reason Rick gave for using the new style open() command open my $fh, '>', $filename; as opposed to the old style open(FH, ">$filename"); amongst other things. -- Regards, Faber Fedor President Linux New Jersey, Inc. 908-320-0357 800-706-0701 http://www.linuxnj.com From perl.abe at rjbs.manxome.org Wed Aug 13 12:25:50 2008 From: perl.abe at rjbs.manxome.org (Ricardo SIGNES) Date: Wed, 13 Aug 2008 15:25:50 -0400 Subject: [ABE.pm] searching the archives In-Reply-To: <20080813191859.GA20782@neptune.faber.nom> References: <20080813191859.GA20782@neptune.faber.nom> Message-ID: <20080813192550.GA25963@cancer.codesimply.com> * "Faber J. Fedor" [2008-08-13T15:18:59] > How do I search the ML archives? Curses! http://mail.pm.org/pipermail/abe-pm/ No search there, and we're not loaded into perl.markmail.org > I want to look up the reason Rick gave for using the new style open() > command > > open my $fh, '>', $filename; > > as opposed to the old style > > open(FH, ">$filename"); For one thing, having a string that contains multiple args is awful. It's like if you had to say: $sum = add_up("1:2:3:10"); # returns 16 More importantly, though, the old style creates a global filehandle. Globals are evil. -- rjbs From faber at linuxnj.com Wed Aug 13 12:33:12 2008 From: faber at linuxnj.com (Faber J. Fedor) Date: Wed, 13 Aug 2008 15:33:12 -0400 Subject: [ABE.pm] searching the archives In-Reply-To: <20080813192550.GA25963@cancer.codesimply.com> References: <20080813191859.GA20782@neptune.faber.nom> <20080813192550.GA25963@cancer.codesimply.com> Message-ID: <20080813193312.GA20846@neptune.faber.nom> On 13/08/08 15:25 -0400, Ricardo SIGNES wrote: > * "Faber J. Fedor" [2008-08-13T15:18:59] > > How do I search the ML archives? > > Curses! Are you swearing or telling me to use curses? :-) > http://mail.pm.org/pipermail/abe-pm/ > No search there, Duh! > More importantly, though, the old style creates a global filehandle. Globals > are evil. Oh. I thought it was a more nuanced than that. Thanks. -- Regards, Faber Fedor President Linux New Jersey, Inc. 908-320-0357 800-706-0701 http://www.linuxnj.com From waltman at pobox.com Wed Aug 13 12:44:16 2008 From: waltman at pobox.com (Walt Mankowski) Date: Wed, 13 Aug 2008 15:44:16 -0400 Subject: [ABE.pm] searching the archives In-Reply-To: <20080813193312.GA20846@neptune.faber.nom> References: <20080813191859.GA20782@neptune.faber.nom> <20080813192550.GA25963@cancer.codesimply.com> <20080813193312.GA20846@neptune.faber.nom> Message-ID: <20080813194416.GC30052@mawode.com> On Wed, Aug 13, 2008 at 03:33:12PM -0400, Faber J. Fedor wrote: > > More importantly, though, the old style creates a global filehandle. Globals > > are evil. > > Oh. I thought it was a more nuanced than that. Thanks. More advantages: * lexical filehandles are easier to pass to subroutines * when a lexical filehandle goes out of scope, the corresponding file is automatically closed There's some more discussion of this issue at http://www.perlfoundation.org/perl5/index.cgi?bareword_uppercase_filehandles Walt From hdp at pobox.com Wed Aug 13 12:45:42 2008 From: hdp at pobox.com (Hans Dieter Pearcey) Date: Wed, 13 Aug 2008 15:45:42 -0400 Subject: [ABE.pm] searching the archives In-Reply-To: <20080813192550.GA25963@cancer.codesimply.com> References: <20080813191859.GA20782@neptune.faber.nom> <20080813192550.GA25963@cancer.codesimply.com> Message-ID: <20080813194541.GK27593@glaive.weftsoar.net> On Wed, Aug 13, 2008 at 03:25:50PM -0400, Ricardo SIGNES wrote: > > I want to look up the reason Rick gave for using the new style open() > > command > > > > open my $fh, '>', $filename; > > > > as opposed to the old style > > > > open(FH, ">$filename"); > > For one thing, having a string that contains multiple args is awful. It's like > if you had to say: > > $sum = add_up("1:2:3:10"); # returns 16 > > More importantly, though, the old style creates a global filehandle. Globals > are evil. Well, there are two things there. You can have 2-arg open and a lexical or 3-arg and a global. Both 2-arg open and global filehandles are bad. 2-arg open is especially scary when opening a pipe. hdp. From faber at linuxnj.com Wed Aug 13 13:04:17 2008 From: faber at linuxnj.com (Faber J. Fedor) Date: Wed, 13 Aug 2008 16:04:17 -0400 Subject: [ABE.pm] searching the archives In-Reply-To: <20080813194416.GC30052@mawode.com> References: <20080813191859.GA20782@neptune.faber.nom> <20080813192550.GA25963@cancer.codesimply.com> <20080813193312.GA20846@neptune.faber.nom> <20080813194416.GC30052@mawode.com> Message-ID: <20080813200417.GA21518@neptune.faber.nom> On 13/08/08 15:44 -0400, Walt Mankowski wrote: > On Wed, Aug 13, 2008 at 03:33:12PM -0400, Faber J. Fedor wrote: > > > More importantly, though, the old style creates a global filehandle. Globals > > > are evil. > > > > Oh. I thought it was a more nuanced than that. Thanks. > > More advantages: > > * lexical filehandles are easier to pass to subroutines Right, because to pass global filehandles you had to use typelobs, right? > * when a lexical filehandle goes out of scope, the corresponding file > is automatically closed That's important enough to go into the lecture notes. > There's some more discussion of this issue at > http://www.perlfoundation.org/perl5/index.cgi?bareword_uppercase_filehandles Thanks. -- Regards, Faber Fedor President Linux New Jersey, Inc. 908-320-0357 800-706-0701 http://www.linuxnj.com From perl.abe at rjbs.manxome.org Wed Aug 13 13:08:32 2008 From: perl.abe at rjbs.manxome.org (Ricardo SIGNES) Date: Wed, 13 Aug 2008 16:08:32 -0400 Subject: [ABE.pm] searching the archives In-Reply-To: <20080813200417.GA21518@neptune.faber.nom> References: <20080813191859.GA20782@neptune.faber.nom> <20080813192550.GA25963@cancer.codesimply.com> <20080813193312.GA20846@neptune.faber.nom> <20080813194416.GC30052@mawode.com> <20080813200417.GA21518@neptune.faber.nom> Message-ID: <20080813200832.GA26148@cancer.codesimply.com> * "Faber J. Fedor" [2008-08-13T16:04:17] > > * lexical filehandles are easier to pass to subroutines > > Right, because to pass global filehandles you had to use typelobs, > right? Yeah, that's sort of an issue with any kind of filehandle passing. It's probably a red herring, here. -- rjbs From faber at linuxnj.com Thu Aug 14 17:44:36 2008 From: faber at linuxnj.com (Faber J. Fedor) Date: Thu, 14 Aug 2008 20:44:36 -0400 Subject: [ABE.pm] Fun(ny) perl stuff? Message-ID: <20080815004436.GA7336@neptune.faber.nom> Any suggestions for silly/funny/surprising things Perl related that I can show my class? I've got Acme::Bleach. I didn't see anything else in there but I'm going to go look again. Some surprising examples of Perl Golf or JAPH stuff, maybe? -- Regards, Faber Fedor President Linux New Jersey, Inc. 908-320-0357 800-706-0701 http://www.linuxnj.com From perl.abe at rjbs.manxome.org Thu Aug 14 18:48:00 2008 From: perl.abe at rjbs.manxome.org (Ricardo SIGNES) Date: Thu, 14 Aug 2008 21:48:00 -0400 Subject: [ABE.pm] Fun(ny) perl stuff? In-Reply-To: <20080815004436.GA7336@neptune.faber.nom> References: <20080815004436.GA7336@neptune.faber.nom> Message-ID: <20080815014800.GB31979@cancer.codesimply.com> * "Faber J. Fedor" [2008-08-14T20:44:36] > Any suggestions for silly/funny/surprising things Perl related that I > can show my class? > > I've got Acme::Bleach. I didn't see anything else in there but I'm > going to go look again. Acme::ProgressBar is always fun. Acme::Rant, Acme::EyeDrops. Acme::MetaSyntactic. Acme::ComeFrom for the INTERCAL fans in the audience. -- rjbs From andy at hexten.net Fri Aug 15 01:05:56 2008 From: andy at hexten.net (Andy Armstrong) Date: Fri, 15 Aug 2008 10:05:56 +0200 Subject: [ABE.pm] Fun(ny) perl stuff? In-Reply-To: <20080815014800.GB31979@cancer.codesimply.com> References: <20080815004436.GA7336@neptune.faber.nom> <20080815014800.GB31979@cancer.codesimply.com> Message-ID: <19A2F3DA-921B-4E83-A580-523ECDE7763E@hexten.net> On 15 Aug 2008, at 03:48, Ricardo SIGNES wrote: > Acme::ProgressBar is always fun. Acme::Rant, Acme::EyeDrops. > Acme::MetaSyntactic. Acme::ComeFrom for the INTERCAL fans in the > audience. http://returnvalues.useperl.at/ :) -- Andy Armstrong, Hexten From faber at linuxnj.com Fri Aug 15 10:19:09 2008 From: faber at linuxnj.com (Faber J. Fedor) Date: Fri, 15 Aug 2008 13:19:09 -0400 Subject: [ABE.pm] 'for' statement Q Message-ID: <20080815171909.GA8696@neptune.faber.nom> Yes, a question about the 'for' statement. Can you beleive I'm teaching a Perl class on Monday? :-) I thought this was a typo for($c, $m, $y) { $_-= $k; } where 'for' was written when the author (Dominus) meant to type 'foreach'. But it turns out to work just like a foreach, IOW, it iterates over the list and $_ is assigned $c then $m then $y. Why does that work? My theory is this: First note that the $c,$m,$y are not the traditional three elements of a for() loop (initial expression, incrementor, test) because those are separated by semi-colons. Here the $c, $m, $y are the initial expression. Now, if the initial expression is true, the block will be executed. That explains why the block is executed the first time ($_ <- $c). But why is the block executed two more times? My guess is the initial expression is seen in a list context and the code block as a reference, i.e. a scalar, and the scalar is applied to each element in the list. That would explain why 'print $_ for(0)' produces an output even though the initial expression is false, n'est pas? -- Regards, Faber Fedor President Linux New Jersey, Inc. 908-320-0357 800-706-0701 http://www.linuxnj.com From waltman at pobox.com Fri Aug 15 10:29:57 2008 From: waltman at pobox.com (Walt Mankowski) Date: Fri, 15 Aug 2008 13:29:57 -0400 Subject: [ABE.pm] 'for' statement Q In-Reply-To: <20080815171909.GA8696@neptune.faber.nom> References: <20080815171909.GA8696@neptune.faber.nom> Message-ID: <20080815172957.GD8469@mawode.com> On Fri, Aug 15, 2008 at 01:19:09PM -0400, Faber J. Fedor wrote: > Yes, a question about the 'for' statement. Can you beleive I'm teaching > a Perl class on Monday? :-) > > I thought this was a typo > > for($c, $m, $y) { $_-= $k; } > > where 'for' was written when the author (Dominus) meant to type 'foreach'. > But it turns out to work just like a foreach, IOW, it iterates over the > list and $_ is assigned $c then $m then $y. That's because "foreach" and "for" are equivalent. From perlsyn: The "foreach" keyword is actually a synonym for the "for" keyword, so you can use "foreach" for readability or "for" for brevity. (Or because the Bourne shell is more familiar to you than csh, so writing "for" comes more naturally.) > Why does that work? My theory is this: > > First note that the $c,$m,$y are not the traditional three elements of a > for() loop (initial expression, incrementor, test) because those are > separated by semi-colons. Here the $c, $m, $y are the initial > expression. > > Now, if the initial expression is true, the block will be executed. That > explains why the block is executed the first time ($_ <- $c). But why > is the block executed two more times? My guess is the initial expression > is seen in a list context and the code block as a reference, i.e. a > scalar, and the scalar is applied to each element in the list. > > That would explain why 'print $_ for(0)' produces an output even though > the initial expression is false, n'est pas? I think it's just that it's treating whatever's in the parens as a list, and iterating over that list. Walt From perl.abe at rjbs.manxome.org Fri Aug 15 10:34:49 2008 From: perl.abe at rjbs.manxome.org (Ricardo SIGNES) Date: Fri, 15 Aug 2008 13:34:49 -0400 Subject: [ABE.pm] 'for' statement Q In-Reply-To: <20080815172957.GD8469@mawode.com> References: <20080815171909.GA8696@neptune.faber.nom> <20080815172957.GD8469@mawode.com> Message-ID: <20080815173449.GA2515@cancer.codesimply.com> * Walt Mankowski [2008-08-15T13:29:57] > On Fri, Aug 15, 2008 at 01:19:09PM -0400, Faber J. Fedor wrote: > > But it turns out to work just like a foreach, IOW, it iterates over the > > list and $_ is assigned $c then $m then $y. > > That's because "foreach" and "for" are equivalent. which means you can also: for (my $i = 0; $i < 10; $i++) { say $i; } You *can't* however say: say $i for (my $i = 0; $i < 10; $i++); for various reasons, including the nature of lexical scope and assignment. That and I think the parser barfs. -- rjbs From waltman at pobox.com Fri Aug 15 10:37:03 2008 From: waltman at pobox.com (Walt Mankowski) Date: Fri, 15 Aug 2008 13:37:03 -0400 Subject: [ABE.pm] 'for' statement Q In-Reply-To: <20080815172957.GD8469@mawode.com> References: <20080815171909.GA8696@neptune.faber.nom> <20080815172957.GD8469@mawode.com> Message-ID: <20080815173703.GE8469@mawode.com> On Fri, Aug 15, 2008 at 01:29:57PM -0400, Walt Mankowski wrote: > On Fri, Aug 15, 2008 at 01:19:09PM -0400, Faber J. Fedor wrote: > > Yes, a question about the 'for' statement. Can you beleive I'm teaching > > a Perl class on Monday? :-) > > > > I thought this was a typo > > > > for($c, $m, $y) { $_-= $k; } > > > > where 'for' was written when the author (Dominus) meant to type 'foreach'. > > But it turns out to work just like a foreach, IOW, it iterates over the > > list and $_ is assigned $c then $m then $y. > > That's because "foreach" and "for" are equivalent. From perlsyn: > > The "foreach" keyword is actually a synonym for the "for" keyword, > so you can use "foreach" for readability or "for" for brevity. (Or > because the Bourne shell is more familiar to you than csh, so > writing "for" comes more naturally.) > > > Why does that work? My theory is this: > > > > First note that the $c,$m,$y are not the traditional three elements of a > > for() loop (initial expression, incrementor, test) because those are > > separated by semi-colons. Here the $c, $m, $y are the initial > > expression. > > > > Now, if the initial expression is true, the block will be executed. That > > explains why the block is executed the first time ($_ <- $c). But why > > is the block executed two more times? My guess is the initial expression > > is seen in a list context and the code block as a reference, i.e. a > > scalar, and the scalar is applied to each element in the list. > > > > That would explain why 'print $_ for(0)' produces an output even though > > the initial expression is false, n'est pas? > > I think it's just that it's treating whatever's in the parens as a > list, and iterating over that list. It's not clear you know this from what you said, but this is the same idea as this: my @list = ($c, $m, $y); for (@list) { print "$_\n"; } If you're not familiar with that syntax, you've got a lot of catching up to do before you teach this class... :) Walt From perl.abe at rjbs.manxome.org Fri Aug 15 10:44:36 2008 From: perl.abe at rjbs.manxome.org (Ricardo SIGNES) Date: Fri, 15 Aug 2008 13:44:36 -0400 Subject: [ABE.pm] curriculum ideas In-Reply-To: <20080812221335.GB7878@neptune.faber.nom> References: <20080812221335.GB7878@neptune.faber.nom> Message-ID: <20080815174436.GA2566@cancer.codesimply.com> * "Faber J. Fedor" [2008-08-12T18:13:35] > So I'm looking for ideas on what to do with these guys. I'm looking for > interesting ideas to go over and/or hack together. I'm going > to pour over HOP and "Advanced Perl Programming" for ideas. A few > things I've already come up with are complex data structures (AoA, HoH, > etc.), caching of data, and some more complicated examples of closures. > Have them debug a Perl script that's *really* tricky/buggy ? autobox.pm, autobox::Core -- rjbs From faber at linuxnj.com Fri Aug 15 10:56:16 2008 From: faber at linuxnj.com (Faber J. Fedor) Date: Fri, 15 Aug 2008 13:56:16 -0400 Subject: [ABE.pm] 'for' statement Q In-Reply-To: <20080815172957.GD8469@mawode.com> References: <20080815171909.GA8696@neptune.faber.nom> <20080815172957.GD8469@mawode.com> Message-ID: <20080815175616.GB8696@neptune.faber.nom> On 15/08/08 13:29 -0400, Walt Mankowski wrote: > On Fri, Aug 15, 2008 at 01:19:09PM -0400, Faber J. Fedor wrote: > > I thought this was a typo > > > > for($c, $m, $y) { $_-= $k; } > > > > where 'for' was written when the author (Dominus) meant to type 'foreach'. > > But it turns out to work just like a foreach, IOW, it iterates over the > > list and $_ is assigned $c then $m then $y. > > That's because "foreach" and "for" are equivalent. From perlsyn: Interesting. That means I can have an incrementor and a test condition in my foreachs! I'm going to have to play with that...