From MichaelRWolf at att.net Mon Oct 13 15:03:26 2008 From: MichaelRWolf at att.net (Michael R. Wolf) Date: Mon, 13 Oct 2008 15:03:26 -0700 Subject: SPUG: "Boolean" return values Message-ID: <48F3C5AE.8000200@att.net> Does anyone know the motivation for the return values from the boolean operators? true returns (numeric) 1 false returns (string) '' Why not just 0 and 1? Why the mix of numeric and string? Is it just one of those "hysterical" (i.e. historically funny) laws of unintended consequences? Given that it's usually embedded in an 'if' or 'while' statement, I really don't care what the return values are, just as long as they work, but is there some clever use for this non-obvious choice of true and false? Thanks... From cmeyer at helvella.org Mon Oct 13 15:32:35 2008 From: cmeyer at helvella.org (Colin Meyer) Date: Mon, 13 Oct 2008 15:32:35 -0700 Subject: SPUG: "Boolean" return values In-Reply-To: <48F3C5AE.8000200@att.net> References: <48F3C5AE.8000200@att.net> Message-ID: <20081013223235.GF31390@infula.helvella.org> On Mon, Oct 13, 2008 at 03:03:26PM -0700, Michael R. Wolf wrote: > Does anyone know the motivation for the return values from the boolean > operators? We have boolean context, but not boolean operators. Maybe "!". Most of the logical operators have return values based on their input. > > true returns (numeric) 1 > false returns (string) '' > > Why not just 0 and 1? Why the mix of numeric and string? They return a multi-valued scalar: > perl -MDevel::Peek -le'Dump( ! "" ); Dump( ! 0 );' SV = PVNV(0x605060) at 0x2af2764040d0 REFCNT = 2147483647 FLAGS = (IOK,NOK,POK,READONLY,pIOK,pNOK,pPOK) IV = 1 NV = 1 PV = 0x606030 "1"\0 CUR = 1 LEN = 8 SV = PVNV(0x605060) at 0x2af2764040d0 REFCNT = 2147483647 FLAGS = (IOK,NOK,POK,READONLY,pIOK,pNOK,pPOK) IV = 1 NV = 1 PV = 0x606030 "1"\0 CUR = 1 LEN = 8 In a string context, that will be "1"; Integer or real: 1; Boolean: true; The return values for false are similarly multivalued. -Colin. From cmeyer at helvella.org Mon Oct 13 16:06:10 2008 From: cmeyer at helvella.org (Colin Meyer) Date: Mon, 13 Oct 2008 16:06:10 -0700 Subject: SPUG: "Boolean" return values In-Reply-To: References: <48F3C5AE.8000200@att.net> <20081013223235.GF31390@infula.helvella.org> Message-ID: <20081013230610.GG31390@infula.helvella.org> On Mon, Oct 13, 2008 at 03:58:22PM -0700, craig at seaperl.com wrote: > The reason that I've always heard was that in an IF condition you could do > TRUE if the condition returned a positive number and would be FALSE if it > was a numeric 0 or a string. Perl does that sort of conversion so that if > you have a string of "345" that it could be evaluated as a NUMERIC 345 and > counting as TRUE but that something like "345r2" would be evaluated as a > string and be considered FALSE. That's not quite true: perl -le'print "345r2" ? "true" : "false"' perldoc perlsyn Truth and Falsehood The number 0, the strings '0' and '', the empty list "()", and "undef" are all false in a boolean context. All other values are true. Negation of a true value by "!" or "not" returns a special false value. When evaluated as a string it is treated as '', but as a number, it is treated as 0. -Colin. From MichaelRWolf at att.net Tue Oct 14 00:21:15 2008 From: MichaelRWolf at att.net (Michael R. Wolf) Date: Tue, 14 Oct 2008 00:21:15 -0700 Subject: SPUG: "Boolean" return values In-Reply-To: <20081013223235.GF31390@infula.helvella.org> References: <48F3C5AE.8000200@att.net> <20081013223235.GF31390@infula.helvella.org> Message-ID: <48F4486B.3010205@att.net> Colin Meyer wrote: > On Mon, Oct 13, 2008 at 03:03:26PM -0700, Michael R. Wolf wrote: >> Does anyone know the motivation for the return values from the boolean >> operators? > > We have boolean context, but not boolean operators. Maybe "!". Most of > the logical operators have return values based on their input. > >> true returns (numeric) 1 >> false returns (string) '' >> >> Why not just 0 and 1? Why the mix of numeric and string? > > They return a multi-valued scalar: > > > perl -MDevel::Peek -le'Dump( ! "" ); Dump( ! 0 );' > SV = PVNV(0x605060) at 0x2af2764040d0 > REFCNT = 2147483647 > FLAGS = (IOK,NOK,POK,READONLY,pIOK,pNOK,pPOK) > IV = 1 > NV = 1 > PV = 0x606030 "1"\0 > CUR = 1 > LEN = 8 > SV = PVNV(0x605060) at 0x2af2764040d0 > REFCNT = 2147483647 > FLAGS = (IOK,NOK,POK,READONLY,pIOK,pNOK,pPOK) > IV = 1 > NV = 1 > PV = 0x606030 "1"\0 > CUR = 1 > LEN = 8 > > In a string context, that will be "1"; Integer or real: 1; Boolean: true; Thanks for the reply. It helped me reformulate my question (even if I don't understand all nuances of the underlying C code as reported by Devel::Peek). Boolean (err, 'logical') operator return values, Take 2: The 6 relational operators (both the stringy and numy flavors), and various other logical operators seem to return reasonable values in the IV and NV slots (specifically 1 for "true" and 0 for "false"). I don't understand why the PV slot is "1" for true and "" for false. Why not "1" and "0" so that the stringy value corresponds to the numy value? It's especially confusing to folks (me included) who write code like this: $true = 1 < 100; $false = 100 < 1; print "true is '$true' and false is '$false'\n"; It seems non-parallel, or imbalanced. Can you reframe it for me in a way that makes sense, creates balance, and seems consistent (for some definition of consistent)? To wit.... use Devel::Peek; # Here's what "true" looks like... Dump(! ""); Dump(! 0); Dump(1 < 100); # Here's what "false" looks like... Dump(!! ""); Dump(!! 0); Dump(100 < 1); SV = PVNV(0x10022820) at 0x10012a08 REFCNT = 2147483644 FLAGS = (PADTMP,IOK,NOK,POK,READONLY,pIOK,pNOK,pPOK) IV = 1 NV = 1 PV = 0x10022008 "1"\0 CUR = 1 LEN = 4 SV = PVNV(0x10022c40) at 0x1004fbc0 REFCNT = 1 FLAGS = (PADTMP,IOK,NOK,POK,READONLY,pIOK,pNOK,pPOK) IV = 1 NV = 1 PV = 0x100220f8 "1"\0 CUR = 1 LEN = 4 SV = PVNV(0x10022c70) at 0x1004fcc8 REFCNT = 1 FLAGS = (PADTMP,IOK,NOK,POK,READONLY,pIOK,pNOK,pPOK) IV = 1 NV = 1 PV = 0x10022218 "1"\0 CUR = 1 LEN = 4 SV = PVNV(0x10022808) at 0x100129f0 REFCNT = 2147483645 FLAGS = (PADTMP,IOK,NOK,POK,READONLY,pIOK,pNOK,pPOK) IV = 0 NV = 0 PV = 0x10022004 ""\0 CUR = 0 LEN = 4 SV = PVNV(0x10022c88) at 0x1004fc08 REFCNT = 1 FLAGS = (PADTMP,IOK,NOK,POK,READONLY,pIOK,pNOK,pPOK) IV = 0 NV = 0 PV = 0x1002221c ""\0 CUR = 0 LEN = 4 SV = PVNV(0x10022ca0) at 0x1004fb48 REFCNT = 1 FLAGS = (PADTMP,IOK,NOK,POK,READONLY,pIOK,pNOK,pPOK) IV = 0 NV = 0 PV = 0x10022220 ""\0 CUR = 0 LEN = 4 From MichaelRWolf at att.net Tue Oct 14 08:08:37 2008 From: MichaelRWolf at att.net (Michael R. Wolf) Date: Tue, 14 Oct 2008 08:08:37 -0700 Subject: SPUG: "Boolean" return values In-Reply-To: References: <48F3C5AE.8000200@att.net> <20081013223235.GF31390@infula.helvella.org> Message-ID: <48F4B5F5.4030100@att.net> craig at seaperl.com wrote: > The reason that I've always heard was that in an IF condition you could > do TRUE if the condition returned a positive number and would be FALSE > if it was a numeric 0 or a string. Perl does that sort of conversion so > that if you have a string of "345" that it could be evaluated as a > NUMERIC 345 and counting as TRUE but that something like "345r2" would > be evaluated as a string and be considered FALSE. Your understanding of strings in a boolean context isn't correct. Here's a simple chunk of code that disproves your assertion: if ("345r2") { print "The string was true\n"; } else { print "The string was false\n"; } Negative numbers are also true. There are only 2 false numbers: 0 and 0.0. Some would argue that that is only one number, but this shows that the internal representation is different, even if their use is practically identical. perl -MDevel::Peek -le "Dump(0); Dump(0.0);" SV = IV(0x10023bc8) at 0x10023bc8 REFCNT = 1 FLAGS = (PADTMP,IOK,READONLY,pIOK) IV = 0 SV = NV(0x10063810) at 0x1004f650 REFCNT = 1 FLAGS = (PADTMP,NOK,READONLY,pNOK) NV = 0 In practice, most strings are true. I know of only 3 false strings: 1. '', the empty string 2. '0', the string containing only a single zero 3. "\000", the ASCII NUL character (AKA chr(0)). From rjk-spug at tamias.net Tue Oct 14 08:18:45 2008 From: rjk-spug at tamias.net (Ronald J Kimball) Date: Tue, 14 Oct 2008 11:18:45 -0400 Subject: SPUG: "Boolean" return values In-Reply-To: <48F4B5F5.4030100@att.net> References: <48F3C5AE.8000200@att.net> <20081013223235.GF31390@infula.helvella.org> <48F4B5F5.4030100@att.net> Message-ID: <20081014151845.GB16999@penkwe.pair.com> On Tue, Oct 14, 2008 at 08:08:37AM -0700, Michael R. Wolf wrote: > In practice, most strings are true. I know of only 3 false strings: > 1. '', the empty string > 2. '0', the string containing only a single zero > 3. "\000", the ASCII NUL character (AKA chr(0)). > There are only two false strings. "\000" is true. This is explained very succinctly in the documentation, specifically perlsyn: Truth and Falsehood The number 0, the strings '0' and '', the empty list "()", and "undef" are all false in a boolean context. All other values are true. Negation of a true value by "!" or "not" returns a special false value. When evaluated as a string it is treated as '', but as a number, it is treated as 0. Ronald From m3047 at inwa.net Tue Oct 14 08:37:22 2008 From: m3047 at inwa.net (Fred Morris) Date: Tue, 14 Oct 2008 08:37:22 -0700 Subject: SPUG: 0E0 Re: "Boolean" return values In-Reply-To: <48F4B5F5.4030100@att.net> References: <48F3C5AE.8000200@att.net> <48F4B5F5.4030100@att.net> Message-ID: <200810140837.22854.m3047@inwa.net> Indeed, '0E0' (scientific exponent notation floating point) evaluates to zero... but is not false. You can argue about the sense or ideosyncracy of this (is sense always orderly and composed, and does ideosyncratic == nonsense? ahh philosophy!) but it is put to practical use. When you use DBI->connect()->do() the number of records affected is returned as the function value if the operation succeeds... otherwise the return value tests false. When zero records are affected (but the operation was deemed successful) '0E0' is returned so that sense is preserved and the operation doesn't return false. Does DBI have its lipstick on straight, or is trying to enforce strict type checking on built-in types lipstick on a pig? Does it matter to the pig (other than to annoy it, what with all the fussing about), or is it solely something done for the beholder? On Tuesday 14 October 2008 08:08, Michael R. Wolf wrote: > [...] > In practice, most strings are true. I know of only 3 false strings: > 1. '', the empty string > 2. '0', the string containing only a single zero > 3. "\000", the ASCII NUL character (AKA chr(0)). -- Fred Morris http://www.inwa.net/~m3047/contact.html From cmeyer at helvella.org Tue Oct 14 08:51:21 2008 From: cmeyer at helvella.org (Colin Meyer) Date: Tue, 14 Oct 2008 08:51:21 -0700 Subject: SPUG: "Boolean" return values In-Reply-To: <48F4486B.3010205@att.net> References: <48F3C5AE.8000200@att.net> <20081013223235.GF31390@infula.helvella.org> <48F4486B.3010205@att.net> Message-ID: <20081014155121.GO31390@infula.helvella.org> On Tue, Oct 14, 2008 at 12:21:15AM -0700, Michael R. Wolf wrote: > > Thanks for the reply. It helped me reformulate my question (even if I > don't understand all nuances of the underlying C code as reported by > Devel::Peek). Er, yeah. I guess that everyone doesn't have the same level of curiosity about the internal workings of Perl. I'm compelled to use tools like Devel::Peek to enhance my understanding of what is occurring when I ask Perl to do various things. My curiosity level is still small, relative to some folks, like Josh, who has sacrificed several of his precious and limited sanity points to further his understanding of what is happening and how Perl does it. One thing to keep in mind is that Perl scalars are not the simple values that they handily appear to be, when you are using them. In fact, they are complex objects that behave differently in different contexts. They are also super-optimized, both for speed and for reasonably small memory use (given their capabilities). In fact, Perl scalars are not one class of object, but a whole family of classes, the best one being used at any moment, but might morph into one of the other scalar types, when it becomes necessary. So, a Perl scalar may have several values, an integer, a floating point number, a string value or a reference. This is a simplification, really. Perl overloads these values like crazy (really, crazy). In order to keep track of how the values have been used, and which are still valid, Or, you could not keep all that nonsense about scalars in mind, and perhaps save your sanity. :) If your 401k is already so low that you've already lost all sense of caution, then you might be interested in perusing: perldoc perlguts > > Boolean (err, 'logical') operator return values, Take 2: The concept of boolean, while quite natural to any logical thinker, is something that got a little muddled in Perl5. The perlsyn manpage says, The number 0, the strings '0' and '', the empty list "()", and "undef" are all false in a boolean context. All other values are true. This is the most important thing to keep in mind whenever dealing with "boolean" values or using "boolean" / "logical" operators or conditional constructs. > > The 6 relational operators (both the stringy and numy flavors), and > various other logical operators seem to return reasonable values in the > IV and NV slots (specifically 1 for "true" and 0 for "false"). I don't > understand why the PV slot is "1" for true and "" for false. Why not > "1" and "0" so that the stringy value corresponds to the numy value? Ah, that's a good question. I really don't know the answer. > > It's especially confusing to folks (me included) who write code like this: > > $true = 1 < 100; > $false = 100 < 1; > > print "true is '$true' and false is '$false'\n"; > > It seems non-parallel, or imbalanced. Can you reframe it for me in a > way that makes sense, creates balance, and seems consistent (for some > definition of consistent)? I guess that it makes sense to me. In regular code, I don't have the desire to print out the values of $true and $false. I'd be more inclined to use them in a boolean context, and write something like: print 'Your number is ', ( $num < 100 ? 'less' : 'greater' ), ' than 100'; If I'm feeling more curious or unsane, I'll use a tool like Devel::Peek to have a look at what the thing really is. -Colin. From charles.e.derykus at boeing.com Tue Oct 14 08:56:57 2008 From: charles.e.derykus at boeing.com (DeRykus, Charles E) Date: Tue, 14 Oct 2008 08:56:57 -0700 Subject: SPUG: 0E0 Re: "Boolean" return values In-Reply-To: <200810140837.22854.m3047@inwa.net> References: <48F3C5AE.8000200@att.net><48F4B5F5.4030100@att.net> <200810140837.22854.m3047@inwa.net> Message-ID: > Indeed, '0E0' (scientific exponent notation floating point) evaluates to zero... but is not false. > You can argue about the sense or ideosyncracy of this (is sense always orderly and composed, and does ideosyncratic > == > nonsense? ahh philosophy!) but it is put to practical use. > When you use DBI->connect()->do() the number of records affected is returned as the function value if the operation > succeeds... otherwise the return value tests false. When zero records are affected (but the operation was deemed > successful) '0E0' is returned so that sense is preserved and the operation doesn't return false. > Does DBI have its lipstick on straight, or is trying to enforce strict type checking on built-in types lipstick on > a pig? Does it matter to the pig (other than to annoy it, what with all the fussing about), or is it solely something > done for the beholder? Perl even provides its own "lipstick for a pig" in the spirit of '0E0': $ perl -wle 'print "true" if "0 but true"' true $ perl -wle 'print "0 but true" + 1' 1 >From 'perldoc -f fcntl': You don't have to check for "defined" on the return from "fnctl". Like "ioctl", it maps a "0" return from the system call into ""0 but true"" in Perl. This string is true in boolean context and "0" in numeric context. It is also exempt from the normal -w warnings on improper numeric conversions. -- Charles DeRykus From david.dyck at fluke.com Tue Oct 14 09:27:12 2008 From: david.dyck at fluke.com (David Dyck) Date: Tue, 14 Oct 2008 09:27:12 -0700 (PDT) Subject: SPUG: 0E0 Re: "Boolean" return values In-Reply-To: References: <48F3C5AE.8000200@att.net><48F4B5F5.4030100@att.net><200810140837.22854.m3047@inwa.net> Message-ID: On Tue, 14 Oct 2008 at 08:56 -0700, charles.e.derykus at ... wrote: >> Indeed, '0E0' (scientific exponent notation floating point) evaluates > to zero... but is not false. > > Perl even provides its own "lipstick for a pig" in the spirit of '0E0': > > $ perl -wle 'print "true" if "0 but true"' > true > > $ perl -wle 'print "0 but true" + 1' > 1 Another place where perl (ever since perl1) uses the "E0" special flag is in the ".." range operator (The "0 but true" seems to have started around perl3) see perldoc perlop: Range Operators Binary ".." is the range operator, .... ... The final sequence number in a range has the string "E0" appended to it, which doesn't affect its numeric value, but gives you something to search for if you want to exclude the endpoint. ... From mark.mertel at yahoo.com Tue Oct 14 09:32:47 2008 From: mark.mertel at yahoo.com (mark.mertel at yahoo.com) Date: Tue, 14 Oct 2008 09:32:47 -0700 (PDT) Subject: SPUG: 0E0 Re: "Boolean" return values Message-ID: <227553.89650.qm@web50103.mail.re2.yahoo.com> on a not too unrelated tangent - Config::General allows for 'true', 'ok', '1', 'yes' as true values, and 'false', 'not ok', 0, 'no' as false values --- Mark Mertel 206.441.4663 mark.mertel at yahoo.com ----- Original Message ---- From: David Dyck To: "DeRykus, Charles E" Cc: spug-list at pm.org Sent: Tuesday, October 14, 2008 9:27:12 AM Subject: Re: SPUG: 0E0 Re: "Boolean" return values On Tue, 14 Oct 2008 at 08:56 -0700, charles.e.derykus at ... wrote: >> Indeed, '0E0' (scientific exponent notation floating point) evaluates > to zero... but is not false. > > Perl even provides its own "lipstick for a pig" in the spirit of '0E0': > > $ perl -wle 'print "true" if "0 but true"' > true > > $ perl -wle 'print "0 but true" + 1' > 1 Another place where perl (ever since perl1) uses the "E0" special flag is in the ".." range operator (The "0 but true" seems to have started around perl3) see perldoc perlop: Range Operators Binary ".." is the range operator, .... ... The final sequence number in a range has the string "E0" appended to it, which doesn't affect its numeric value, but gives you something to search for if you want to exclude the endpoint. ... _____________________________________________________________ Seattle Perl Users Group Mailing List POST TO: spug-list at pm.org SUBSCRIPTION: http://mail.pm.org/mailman/listinfo/spug-list MEETINGS: 3rd Tuesdays WEB PAGE: http://seattleperl.org/ From cmeyer at helvella.org Tue Oct 14 13:42:17 2008 From: cmeyer at helvella.org (Colin Meyer) Date: Tue, 14 Oct 2008 13:42:17 -0700 Subject: SPUG: "Boolean" return values In-Reply-To: References: <20081014155121.GO31390@infula.helvella.org> Message-ID: <20081014204216.GR31390@infula.helvella.org> On Tue, Oct 14, 2008 at 01:13:45PM -0700, Andrew Sweger wrote: > On Tue, 14 Oct 2008, Colin Meyer wrote: > > > print 'Your number is ', > > ( $num < 100 ? 'less' : 'greater' ), > > ' than 100'; > > You don't work in the financial sector by any chance, do you? > > my $num = 100; > print 'Your number is ', > ( $num < 100 ? 'less' : 'greater' ), > ' than 100'; Heh, nice catch. -Colin. From tallpeak at hotmail.com Tue Oct 14 12:23:15 2008 From: tallpeak at hotmail.com (Aaron West) Date: Tue, 14 Oct 2008 12:23:15 -0700 Subject: SPUG: 0E0 Re: "Boolean" return values In-Reply-To: <227553.89650.qm@web50103.mail.re2.yahoo.com> References: <227553.89650.qm@web50103.mail.re2.yahoo.com> Message-ID: In the config file, only, right? It can't change the language. (Some modules can make some surprising changes to the way Perl works sometimes, so I wasn't quite sure.) http://search.cpan.org/~tlinden/Config-General-2.40/General.pm#SYNOPSIS ... -AutoTrue If set to a true value, then options in your config file, whose values are set to true or false values, will be normalised to 1 or 0 respectively. The following values will be considered as true: yes, on, 1, true The following values will be considered as false: no, off, 0, false This effect is case-insensitive, i.e. both "Yes" or "oN" will result in 1. ... -----Original Message----- From: spug-list-bounces+tallpeak=hotmail.com at pm.org [mailto:spug-list-bounces+tallpeak=hotmail.com at pm.org] On Behalf Of mark.mertel at yahoo.com Sent: Tuesday, October 14, 2008 9:33 AM To: David Dyck; DeRykus, Charles E Cc: spug-list at pm.org Subject: Re: SPUG: 0E0 Re: "Boolean" return values on a not too unrelated tangent - Config::General allows for 'true', 'ok', '1', 'yes' as true values, and 'false', 'not ok', 0, 'no' as false values --- Mark Mertel 206.441.4663 mark.mertel at yahoo.com From andrew at sweger.net Tue Oct 14 13:13:45 2008 From: andrew at sweger.net (Andrew Sweger) Date: Tue, 14 Oct 2008 13:13:45 -0700 (PDT) Subject: SPUG: "Boolean" return values In-Reply-To: <20081014155121.GO31390@infula.helvella.org> Message-ID: On Tue, 14 Oct 2008, Colin Meyer wrote: > print 'Your number is ', > ( $num < 100 ? 'less' : 'greater' ), > ' than 100'; You don't work in the financial sector by any chance, do you? my $num = 100; print 'Your number is ', ( $num < 100 ? 'less' : 'greater' ), ' than 100'; -- Andrew B. Sweger -- The great thing about multitasking is that several things can go wrong at once. From cmeyer at helvella.org Wed Oct 15 11:44:51 2008 From: cmeyer at helvella.org (Colin Meyer) Date: Wed, 15 Oct 2008 11:44:51 -0700 Subject: SPUG: October 2008 Seattle Perl Users Group Meeting Message-ID: <20081015184451.GA19919@infula.helvella.org> October 2008 Seattle Perl Users Group (SPUG) Meeting ==================================================== Topic: Getting Comfortable with the Perl Precedence Table Speaker: Tye McQueen Meeting Date: Tuesday, 21 October 2008 Meeting Time: 6:30 - 8:30 p.m. Location: Marchex - 4th & Pine Cost: Admission is free and open to the public Info: http://seattleperl.org/ ==================================================== Tomorrow, Tuesday, September 16th, is the next meeting of the THE SEATTLE PERL USERS GROUP. Getting Comfortable with the Perl Precedence Table: Help in understanding it, not memorizing it, and making good use of it. The good, the bad, and the ugly of it. And some "best practices" suggestions. Tye says, of his involvement with Perl, "I have been programming Perl since the last days of Perl 3 but have only recently moved to Seattle to enjoy my first ever paid position as a "Perl Programmer". I have made several small contributions to the Perl source code but am most visible in the Perl community of late as one of the absentee landlords of http://PerlMonks.org/ and as the author and/or absentee landlord of several modules including Win32::TieRegistry, Algorithm::Loops, Algorithm:Diff, Acme::ESP, and Devel::EvalError. With regard to the topic of my talk, I am proud to note that I recently convinced Larry Wall to add one more slot to the Perl 6 precedence table (but my talk is about the Perl 5 precedence table)." Pre-Meeting ================ If you are so inclined, please come to the pre-meeting at the Elephant & Castle pub on 5th & Union. We'll be there from 5-6:19PM. Meeting Location ================ Pizza and Beer will be provided at the meeting. Marchex 413 Pine St, Suite 500 Seattle, WA 98101 Contact: Jackie Wolfstone - 206-491-8072 The building is just south of Westlake Center. Enter on 4th Avenue, near Pine street. The entry is near the Dog In The Park hotdog stand. http://www.baylis.org/static/marchex.png Due to all of the shopping around us there is plenty of parking available in garages, but it can be hard to find street parking in the evening. See you there! From cmeyer at helvella.org Wed Oct 15 12:11:15 2008 From: cmeyer at helvella.org (Colin Meyer) Date: Wed, 15 Oct 2008 12:11:15 -0700 Subject: SPUG: October 2008 Seattle Perl Users Group Meeting In-Reply-To: <20081015184451.GA19919@infula.helvella.org> References: <20081015184451.GA19919@infula.helvella.org> Message-ID: <20081015191114.GB19919@infula.helvella.org> On Wed, Oct 15, 2008 at 11:44:51AM -0700, Colin Meyer wrote: > October 2008 Seattle Perl Users Group (SPUG) Meeting > ==================================================== > > Topic: Getting Comfortable with the Perl Precedence Table > Speaker: Tye McQueen > Meeting Date: Tuesday, 21 October 2008 > Meeting Time: 6:30 - 8:30 p.m. > Location: Marchex - 4th & Pine > > Cost: Admission is free and open to the public > Info: http://seattleperl.org/ > > ==================================================== > > Tomorrow, Tuesday, September 16th, is the next meeting of the THE > SEATTLE PERL USERS GROUP. dang it. How about: Tuesday, October 21, is the next meeting of the THE SEATTLE PERL USERS GROUP. -Colin. From MichaelRWolf at att.net Wed Oct 15 12:29:13 2008 From: MichaelRWolf at att.net (Michael R. Wolf) Date: Wed, 15 Oct 2008 12:29:13 -0700 Subject: SPUG: "Boolean" return values In-Reply-To: <20081014151845.GB16999@penkwe.pair.com> References: <48F3C5AE.8000200@att.net> <20081013223235.GF31390@infula.helvella.org> <48F4B5F5.4030100@att.net> <20081014151845.GB16999@penkwe.pair.com> Message-ID: <48F64489.8070303@att.net> Ronald J Kimball wrote: > On Tue, Oct 14, 2008 at 08:08:37AM -0700, Michael R. Wolf wrote: >> In practice, most strings are true. I know of only 3 false strings: >> 1. '', the empty string >> 2. '0', the string containing only a single zero >> 3. "\000", the ASCII NUL character (AKA chr(0)). >> > > There are only two false strings. "\000" is true. I *knew* that there were only two false strings, but yesterday, on a whim, I tried #3 and (to my surprise) found it to be *false*. Unfortunately, I can't recreate that experiment today, so I guess I'm back to my original beliefs, based on the documentation you provided. Anyone know how I may have gotten "\000" to be hint that it's false? From MichaelRWolf at att.net Wed Oct 15 18:34:08 2008 From: MichaelRWolf at att.net (Michael R. Wolf) Date: Wed, 15 Oct 2008 18:34:08 -0700 Subject: SPUG: "Boolean" return values In-Reply-To: <20081014155121.GO31390@infula.helvella.org> References: <48F3C5AE.8000200@att.net> <20081013223235.GF31390@infula.helvella.org> <48F4486B.3010205@att.net> <20081014155121.GO31390@infula.helvella.org> Message-ID: <48F69A10.5040908@att.net> Colin Meyer wrote: > On Tue, Oct 14, 2008 at 12:21:15AM -0700, Michael R. Wolf wrote: >> It's especially confusing to folks (me included) who write code like this: >> >> $true = 1 < 100; >> $false = 100 < 1; >> >> print "true is '$true' and false is '$false'\n"; >> >> It seems non-parallel, or imbalanced. Can you reframe it for me in a >> way that makes sense, creates balance, and seems consistent (for some >> definition of consistent)? > > I guess that it makes sense to me. In regular code, I don't have the > desire to print out the values of $true and $false. I'd be more inclined > to use them in a boolean context, and write something like: > > print 'Your number is ', > ( $num < 100 ? 'less' : 'greater' ), > ' than 100'; I'm not likely to print them to normal users, but I've found that while debugging, it's awkward to have to use a conditional operator (as above) or some other magic just to see them. my $true = 1 < 100; my $false = 100 < 1; print "true is '$true' and false is '$false'\n"; print "\n"; foreach my $answer ($true, $false) { print " raw answer is '$answer'\n"; print "coerced answer is '@{[$answer+0]}'\n"; print "\n"; } I'm so used to Perl's DWIM feature providing me with the freedom to SWIM. Printing return values from logical operators seems to be cutting across the normal DWIM/SWIM that has me working *with* the force instead of across the grain. I know how to make Perl bend to my will, but I'm wondering if there's some higher intelligence that I'm missing so that I can change my mind to fit the deeper insight. Anyone else have a good guess (or even a SWAG) as to why stringy logical values (PV's) are *not* the stringification of the integer and double (IV's and NV's) for the 'false' case, but *are* for the 'true' case? From twists at gmail.com Sat Oct 18 07:50:26 2008 From: twists at gmail.com (Joshua ben Jore) Date: Sat, 18 Oct 2008 07:50:26 -0700 Subject: SPUG: "Boolean" return values In-Reply-To: <48F64489.8070303@att.net> References: <48F3C5AE.8000200@att.net> <20081013223235.GF31390@infula.helvella.org> <48F4B5F5.4030100@att.net> <20081014151845.GB16999@penkwe.pair.com> <48F64489.8070303@att.net> Message-ID: On Wed, Oct 15, 2008 at 12:29 PM, Michael R. Wolf wrote: > Ronald J Kimball wrote: >> >> On Tue, Oct 14, 2008 at 08:08:37AM -0700, Michael R. Wolf wrote: >>> >>> In practice, most strings are true. I know of only 3 false strings: >>> 1. '', the empty string >>> 2. '0', the string containing only a single zero >>> 3. "\000", the ASCII NUL character (AKA chr(0)). >>> >> >> There are only two false strings. "\000" is true. > > I *knew* that there were only two false strings, but yesterday, on a whim, I > tried #3 and (to my surprise) found it to be *false*. Unfortunately, I can't > recreate that experiment today, so I guess I'm back to my original beliefs, > based on the documentation you provided. > > Anyone know how I may have gotten "\000" to be hint that it's false? Perhaps you numified your string. Since the string was non-numeric, you got a zero which is false. This throws a warning when warnings are enabled. $false = 0 + chr 0 Josh From choward at indicium.us Fri Oct 24 00:32:59 2008 From: choward at indicium.us (Christopher Howard) Date: Thu, 23 Oct 2008 23:32:59 -0800 Subject: SPUG: Question about variables in packages Message-ID: <49017A2B.6060306@indicium.us> Hi. I want to use packages in the program I'm working on. Not for creating classes, but just to keep my variables and subroutines in neat, tidy namespaces. But what should the variables look like in the packages? I tried this: use strict; use warnings; package Stuff; $var1 = 10; $var2 = 3; $var3; sub doThis() { ... } ... But then I get the regular reprimand about using globals. I wondered if I was suppose to be doing this: ... $Stuff::var1 = 10; $Stuff::var2 = 3; ... But that seems like a lot of extra typing. And I wondered if I was supposed to be making them lexical with ... my $var1 = 10; my $var2 = 3; ... If they are lexical, will I be able to use them in other scripts? And while we are on the subject, what are my options for using the variables in other scripts? Is this supposed to work?: use Stuff; ... my $sum = $Stuff::var1 + $Stuff::var2; Forgive the newbie questions, but the language of "perldocs package" left me a bit uncertain about what exactly is going on here. -- Christopher Howard choward at indicium.us http://www.indicium.us From keith.reed at philips.com Fri Oct 24 07:37:17 2008 From: keith.reed at philips.com (Reed, Keith) Date: Fri, 24 Oct 2008 16:37:17 +0200 Subject: SPUG: Question about variables in packages In-Reply-To: <49017A2B.6060306@indicium.us> References: <49017A2B.6060306@indicium.us> Message-ID: I believe the reprimand is solely because you didn't put 'my' before your variable declarations. The following seems to work fine... >> use strict; >> use warnings; >> package Stuff; >> >> my $var1 = 10; >> my $var2 = 3; >> my $var3; >> >> >> >> sub doThis() >> { >> print "something\n"; >> $var3 = $var1 + $var2; >> print $var3; >> } >> >> doThis(); Regards, Keith Reed Software Engineer Philips Healthcare Bothell, WA (425) 482-8338 -----Original Message----- From: spug-list-bounces+keith.reed=philips.com at pm.org [mailto:spug-list-bounces+keith.reed=philips.com at pm.org] On Behalf Of Christopher Howard Sent: 2008 Oct 24 12:33 AM To: Seattle Perl Users Group Subject: SPUG: Question about variables in packages Hi. I want to use packages in the program I'm working on. Not for creating classes, but just to keep my variables and subroutines in neat, tidy namespaces. But what should the variables look like in the packages? I tried this: use strict; use warnings; package Stuff; $var1 = 10; $var2 = 3; $var3; sub doThis() { ... } ... But then I get the regular reprimand about using globals. I wondered if I was suppose to be doing this: ... $Stuff::var1 = 10; $Stuff::var2 = 3; ... But that seems like a lot of extra typing. And I wondered if I was supposed to be making them lexical with ... my $var1 = 10; my $var2 = 3; ... If they are lexical, will I be able to use them in other scripts? And while we are on the subject, what are my options for using the variables in other scripts? Is this supposed to work?: use Stuff; ... my $sum = $Stuff::var1 + $Stuff::var2; Forgive the newbie questions, but the language of "perldocs package" left me a bit uncertain about what exactly is going on here. -- Christopher Howard choward at indicium.us http://www.indicium.us _____________________________________________________________ Seattle Perl Users Group Mailing List POST TO: spug-list at pm.org SUBSCRIPTION: http://mail.pm.org/mailman/listinfo/spug-list MEETINGS: 3rd Tuesdays WEB PAGE: http://seattleperl.org/ The information contained in this message may be confidential and legally protected under applicable law. The message is intended solely for the addressee(s). If you are not the intended recipient, you are hereby notified that any use, forwarding, dissemination, or reproduction of this message is strictly prohibited and may be unlawful. If you are not the intended recipient, please contact the sender by return e-mail and destroy all copies of the original message. From sthoenna at efn.org Fri Oct 24 08:11:25 2008 From: sthoenna at efn.org (Yitzchak Scott-Thoennes) Date: Fri, 24 Oct 2008 08:11:25 -0700 (PDT) Subject: SPUG: Question about variables in packages In-Reply-To: <49017A2B.6060306@indicium.us> References: <49017A2B.6060306@indicium.us> Message-ID: <53398.97.113.113.42.1224861085.squirrel@webmail.efn.org> On Fri, October 24, 2008 12:32 am, Christopher Howard wrote: > my $var1 = 10; my $var2 = 3; ... > > If they are lexical, will I be able to use them in other scripts? And > while we are on the subject, what are my options for using the variables in > other scripts? Declare package variables (available globally when qualified with the package name) with our() instead of my(). From mayank_a at students.iiit.ac.in Wed Oct 29 20:27:50 2008 From: mayank_a at students.iiit.ac.in (Mayank Agarwal) Date: Thu, 30 Oct 2008 08:57:50 +0530 (IST) Subject: SPUG: Default action from Except.pm Message-ID: <44164.192.55.52.2.1225337270.squirrel@students.iiit.ac.in> Dear all, I am using Except.pm to automate a interactive script. I searched net, but could not find, how to give a default action, if no expression matches in except construct. My code looks like the below: my $exp = new Expect; $exp->spawn("some_command") $exp->expect(undef, [qr/.*name.*/ => sub { my $fh = shift; $fh->send("myname\n"); exp_continue; } ], [qr/.*city.*/ => sub { my $fh = shift; $fh->send("mycity\n"); exp_continue; } ], ); Thanks and Regards Mayank -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. From telcodev at gmail.com Thu Oct 30 12:14:08 2008 From: telcodev at gmail.com (Joseph Werner) Date: Thu, 30 Oct 2008 12:14:08 -0700 Subject: SPUG: Default action from Except.pm In-Reply-To: <44164.192.55.52.2.1225337270.squirrel@students.iiit.ac.in> References: <44164.192.55.52.2.1225337270.squirrel@students.iiit.ac.in> Message-ID: <4c93055f0810301214r1c3a1acex42386edb71d499b8@mail.gmail.com> Mayank, I see a problem with your phrasing of this problem, as given in your code sample. You are asking for a default action for an undefined timeout [wait forever]. If you just take the Perlish approach and give a pattern that always matches: m{\A.*\z}xms then, well, it will always match, right away. I suspect that what you want is a default case if a key string is not heard in a certain time frame. If you gave a [more] specific example of what you want to do, I might be of more help. Perl Expect shines in networked automation [Telnet, SSH, etc] where timing is unpredictable; there is usually a better way to do your task for most other cases. Here is a couple of Perl scripts that are chatting with each other using Perl Expect. demoExpect.pl loosely follows your code example. some_command.pl prints random sentences at random intervals, and listens for some keywords. Take a look at these examples; listen to the wealth of criticism fellow SPUGers will certainly offer on my examples; consider the implications of timing and clearing [or not clearing] the accumulator and play with the code. Good luck, Joseph Werner Begin demoExpect.pl #!/usr/bin/perl use strict; use warnings; use Expect; my $timeout = 7; my $regx1 = qr /.*name.*/; my $regx2 = qr /.*city.*/; my $exp = new Expect; $exp->spawn("./some_command.pl"); while (1) { my $case = $exp->expect( $timeout, '-re', $regx1, '-re', $regx2 ); $exp->clear_accum(); $case && $case == 1 && do { $exp->send("cmd MYNAME\n"); next; }; $case && $case == 2 && do { $exp->send("act MYCITY\n"); next; }; # Default case: $exp->send("def myDEFAULT\n"); } __END__ Begin some_command.pl #!/usr/bin/perl use strict; use warnings; use Expect; my $commandRe = qr {\A cmd (.*) \z}xms; my $actionRe = qr {\A act (.*) \z}xms; my $defaultRe = qr {\A def (.*) \z}xms; my $exp = Expect->exp_init( \*STDIN ); my $randomSleepInterval = 10; my @randomTextSamples = ( "I am using Except.pm to automate a interactive script.", "My dog is named Boxer", "I adhere to the prevailing CPAN Perl community standards for programming.", "I can think of many uniquie city names in Michigan.", "I would like a report that lists the number of patients by city that visited between a certain date range.", "Seventy weeks are determined upon thy people and upon thy holy city.", "He did say, however, that if they concentrated on the server edition of Ubuntu that they could be profitable in two years.", "This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean.", "Perl is a high-level programming language with an eclectic heritage written by Larry Wall and a cast of thousands.", ); while (1) { print $randomTextSamples[ int( rand( scalar @randomTextSamples ) ) ], "\n"; sleep int( rand($randomSleepInterval) ); my @input = $exp->expect( 0, '-re', $commandRe, '-re', $actionRe, '-re', $defaultRe ); $exp->clear_accum(); next if $input[1]; print "\nI heard ", $input[2], "\n"; } __END__ On Wed, Oct 29, 2008 at 8:27 PM, Mayank Agarwal wrote: > Dear all, > I am using Except.pm to automate a interactive script. I searched net, but > could not find, how to give a default action, if no expression matches in > except construct. > > My code looks like the below: > > my $exp = new Expect; > $exp->spawn("some_command") > $exp->expect(undef, > [qr/.*name.*/ => > sub { > my $fh = shift; > $fh->send("myname\n"); > exp_continue; > } > ], > > > [qr/.*city.*/ => > sub { > my $fh = shift; > $fh->send("mycity\n"); > exp_continue; > } > ], > ); > > > Thanks and Regards > Mayank > > -- > This message has been scanned for viruses and > dangerous content by MailScanner, and is > believed to be clean. > > _____________________________________________________________ > Seattle Perl Users Group Mailing List > POST TO: spug-list at pm.org > SUBSCRIPTION: http://mail.pm.org/mailman/listinfo/spug-list > MEETINGS: 3rd Tuesdays > WEB PAGE: http://seattleperl.org/ > -- I require any third parties to obtain my permission to submit my information to any other party for each such submission. I further require any third party to follow up on any submittal of my information by sending detailed information regarding each such submission to telcodev at gmail.com Joseph Werner