From MichaelRWolf at att.net Wed Oct 1 12:14:34 2003 From: MichaelRWolf at att.net (Michael R. Wolf) Date: Mon Aug 2 21:37:09 2004 Subject: SPUG: Perl accessable ctype.h macros Message-ID: Is there a Perl-accessible interface to ctype.h and it's family of is* macros (i.e. isalpha, isalphanum, isprintable, iswhitespace...)? -- Michael R. Wolf All mammals learn by playing! MichaelRWolf@att.net From cmeyer at helvella.org Wed Oct 1 12:31:47 2003 From: cmeyer at helvella.org (Colin Meyer) Date: Mon Aug 2 21:37:09 2004 Subject: SPUG: Perl accessable ctype.h macros In-Reply-To: ; from MichaelRWolf@att.net on Wed, Oct 01, 2003 at 10:14:34AM -0700 References: Message-ID: <20031001103147.A28843@hobart.helvella.org> On Wed, Oct 01, 2003 at 10:14:34AM -0700, Michael R. Wolf wrote: > > Is there a Perl-accessible interface to ctype.h and it's family of is* > macros (i.e. isalpha, isalphanum, isprintable, iswhitespace...)? See 'perldoc POSIX'. -Colin. From daryn at marinated.org Wed Oct 1 14:54:40 2003 From: daryn at marinated.org (Daryn) Date: Mon Aug 2 21:37:09 2004 Subject: SPUG: sorry! Message-ID: <008501c38855$da421f30$676fa8c0@SPARTA> Hi Spuggers, my apologies to anyone who got a challenge from my spam blocking progam (Spam Arrest). I accidentally deleted SPUG from my authorized mailing lists! From sthoenna at efn.org Wed Oct 1 16:45:16 2003 From: sthoenna at efn.org (Yitzchak Scott-Thoennes) Date: Mon Aug 2 21:37:09 2004 Subject: SPUG: Perl accessable ctype.h macros In-Reply-To: <20031001103147.A28843@hobart.helvella.org> References: <20031001103147.A28843@hobart.helvella.org> Message-ID: <20031001214516.GA4068@efn.org> On Wed, Oct 01, 2003 at 10:31:47AM -0700, Colin Meyer wrote: > On Wed, Oct 01, 2003 at 10:14:34AM -0700, Michael R. Wolf wrote: > > > > Is there a Perl-accessible interface to ctype.h and it's family of is* > > macros (i.e. isalpha, isalphanum, isprintable, iswhitespace...)? > > See 'perldoc POSIX'. You can [[:class:]] in regular expressions. perldoc perlre: The POSIX character class syntax [:class:] is also available. The available classes and their backslash equivalents (if available) are as follows: alpha alnum ascii blank [1] cntrl digit \d graph lower print punct space \s [2] upper word \w [3] xdigit [1] A GNU extension equivalent to "[ \t]", `all horizontal whitespace'. [2] Not exactly equivalent to "\s" since the "[[:space:]]" includes also the (very rare) `vertical tabulator', "\ck", chr(11). [3] A Perl extension, see above. For example use "[:upper:]" to match all the uppercase characters. Note that the "[]" are part of the "[::]" construct, not part of the whole character class. For example: [01[:alpha:]%] matches zero, one, any alphabetic character, and the percentage sign. From itayf at fhcrc.org Wed Oct 1 18:05:00 2003 From: itayf at fhcrc.org (Itay Furman) Date: Mon Aug 2 21:37:09 2004 Subject: SPUG: S.O.S: Sum-Of-Squares (nickname:Help) Message-ID: Hi, I encountered a (literally) small numerical problem during a run of one of my scripts. I have written a small script that reproduces that behavior. It accept as arguments the elements of a vector, calculates the sum-of-squares (sos), and then the normalized length of the vector (should be 1). The output is the 'sos', and the deviation of the normalized length from 1, 'residue'. The problem: for some cases I get a small, non-zero deviation. My question: does any one have some insight or rules-of-a-thumb as to the expected numerical precision in basic arithmetic operations under Perl? I should point out that I have found a simple workaround (see further below), but would like some insight for future reference. Thanks, Itay -- ========================================================================= Itay Furman Fred Hutchinson Cancer Research Center (206) 667-5921 (voice) 1100 Fairview Avenue N., Mailstop D4-100 (206) 667-2917 (fax) P.O. Box 19024 Seattle, WA 98109-1024 ========================================================================= #### Here is my minimal script ##### $ cat test_innerprod.pl #!/usr/local/bin/perl -w use strict; my @elem = @ARGV; # Elements of vector. my $sos = 0; # Sum-Of-Squares $sos += $_**2 foreach (@elem); print "\t"x4, "sos=$sos\tresidue=", 1-$sos/($sos**0.5 * $sos**0.5), "\n"; exit; #### Some examples #### ## OK $ test_innerprod.pl 1 1 1 1 sos=4 residue=0 $ test_innerprod.pl 1 0 0 0 sos=1 residue=0 ## Wrong ! $ test_innerprod.pl 1 1 1 0 sos=3 residue=-2.22044604925031e-16 ## Number of 1's doesn't matter, necessarily $ test_innerprod.pl 1 1 0 0 sos=2 residue=2.22044604925031e-16 ## Order doesn't matter $ test_innerprod.pl 1 0 1 0 sos=2 residue=2.22044604925031e-16 ## Length doesn't matter $ test_innerprod.pl 1 1 0 sos=2 residue=2.22044604925031e-16 ## OK $ test_innerprod.pl 1 0 0 sos=1 residue=0 ## Smallest vector that yields the flow $ test_innerprod.pl 1 1 sos=2 residue=2.22044604925031e-16 ## These don't have to be 1's $ test_innerprod.pl 0.5 0.5 0 0 sos=0.5 residue=2.22044604925031e-16 $ test_innerprod.pl 0.5 0.5 sos=0.5 residue=2.22044604925031e-16 #### My workaround #### $ cat test_innerprod.pl #!/usr/local/bin/perl -w use strict; my @elem = @ARGV; # Elements of vector. my $sos = 0; # Sum-Of-Squares $sos += $_**2 foreach (@elem); print "\t"x4, "sos=$sos\tresidue=", ################################################# # Take the square-root AFTER making the product # # Compare with previous version # # 1-$sos/($sos**0.5 * $sos**0.5) # ################################################# 1-$sos/($sos*$sos)**0.5, "\n"; exit; ## Were wrong before; now OK $ test_innerprod.pl 1 1 1 0 sos=3 residue=0 $ test_innerprod.pl 1 1 0 0 sos=2 residue=0 $ test_innerprod.pl 1 1 0 sos=2 residue=0 $ test_innerprod.pl 1 1 sos=2 residue=0 $ test_innerprod.pl 0.5 0.5 sos=0.5 residue=0 #### End of message. From m3047 at inwa.net Wed Oct 1 21:06:32 2003 From: m3047 at inwa.net (Fred Morris) Date: Mon Aug 2 21:37:09 2004 Subject: SPUG: S.O.S: Sum-Of-Squares (nickname:Help) Message-ID: At 4:05 PM 10/1/03, Itay Furman wrote: >The problem: for some cases I get a small, non-zero deviation. >My question: does any one have some insight or rules-of-a-thumb as to >the expected numerical precision in basic arithmetic operations under Perl? I've been painfully reminded that that is the expected behavior of Perl on several occasions. This can bite you even when trying to figure out what day of the week it is. There is some Math:: stuff. A long time ago I actually took Numerical Analysis, from which I learned: Several techniques for minimizing loss of precision, which contribute to unreadable code in most circumstances. That zero is only zero when you say it is, theoretically speaking.. unless you confine yourself to integer math.. which I don't believe OTS Perl is capable of (however, see Math::BigInt). OTOH, prime numbers are a lot of fun. You probably want some elucidation of exactly what standards-conformant floating point representation Perl uses; I can't help you there. >## Smallest vector that yields the flow >$ test_innerprod.pl 1 1 > sos=2 residue=2.22044604925031e-16 >## These don't have to be 1's >$ test_innerprod.pl 0.5 0.5 0 0 > sos=0.5 residue=2.22044604925031e-16 >$ test_innerprod.pl 0.5 0.5 > sos=0.5 residue=2.22044604925031e-16 > Interesting. Why is it always the same? Anybody got a calculator (with that kind of precision) handy? It does seem to me that your example points the way to a technique for determining the precision (which was probably covered, I don't remember): take 1, and add a value to it which decreases by O(n**x) where n is 10 or 2 and x is a decreasing series integer value until there is no effect. That will tell you the resolution on the platform on which you're running... or else you'll get an underflow error. :-\ Post your (readable) code and I'll run it on a few machines. -- Fred Morris m3047@inwa.net From m3047 at inwa.net Wed Oct 1 21:06:32 2003 From: m3047 at inwa.net (Fred Morris) Date: Mon Aug 2 21:37:09 2004 Subject: SPUG: Perl accessable ctype.h macros Message-ID: At 10:31 AM 10/1/03, Colin Meyer wrote: >On Wed, Oct 01, 2003 at 10:14:34AM -0700, Michael R. Wolf wrote: >> >> Is there a Perl-accessible interface to ctype.h and it's family of is* >> macros (i.e. isalpha, isalphanum, isprintable, iswhitespace...)? > >See 'perldoc POSIX'. Hrmm... 'ferror Use method "IO::Handle::error()" instead...' See, now that would be useful information. Woopsie, can't seem to keep that axe hidden up the sleeve of my open kimono. -- Fred Morris m3047@inwa.net From sthoenna at efn.org Wed Oct 1 22:08:52 2003 From: sthoenna at efn.org (Yitzchak Scott-Thoennes) Date: Mon Aug 2 21:37:09 2004 Subject: SPUG: S.O.S: Sum-Of-Squares (nickname:Help) In-Reply-To: References: Message-ID: On Wed, 1 Oct 2003, Fred Morris wrote: > At 4:05 PM 10/1/03, Itay Furman wrote: > >The problem: for some cases I get a small, non-zero deviation. > >My question: does any one have some insight or rules-of-a-thumb as to > >the expected numerical precision in basic arithmetic operations under Perl? Whatever the underlying C math library uses. You might have better luck using sqrt instead of ** (which will call the C pow() or powl()). But I suspect decent libraries will have .5 special-cased in pow() to end up the same as sqrt(). > I've been painfully reminded that that is the expected behavior of Perl on > several occasions. This can bite you even when trying to figure out what > day of the week it is. There is some Math:: stuff. A long time ago I > actually took Numerical Analysis, from which I learned: > > Several techniques for minimizing loss of precision, which contribute to > unreadable code in most circumstances. > > That zero is only zero when you say it is, theoretically speaking.. unless > you confine yourself to integer math.. which I don't believe OTS Perl is > capable of (however, see Math::BigInt). perldoc integer (not for sqrt or **, though). > OTOH, prime numbers are a lot of fun. > > > You probably want some elucidation of exactly what standards-conformant > floating point representation Perl uses; I can't help you there. Whatever C uses for a double or long double. > >## Smallest vector that yields the flow > >$ test_innerprod.pl 1 1 > > sos=2 residue=2.22044604925031e-16 > >## These don't have to be 1's > >$ test_innerprod.pl 0.5 0.5 0 0 > > sos=0.5 residue=2.22044604925031e-16 > >$ test_innerprod.pl 0.5 0.5 > > sos=0.5 residue=2.22044604925031e-16 > > > > Interesting. Why is it always the same? Anybody got a calculator (with that > kind of precision) handy? $perl -wle'print log(2.22044604925031e-16)/log(2)' -52 i.e. 2.2204...e-16 == 2**-52 So you probably have IEEE doubles with a 53 bit mantissa and the lowest bit is wrong. I suspect your workaround will sometimes fail, too. But I'm not sure what you are trying to accomplish-- x/(x**.5 * x**.5) is supposed to always be one. Are you sure you don't mean to be getting the ratio of the sum of squares to the square of the sum? > It does seem to me that your example points the way to a technique for > determining the precision (which was probably covered, I don't remember): > take 1, and add a value to it which decreases by O(n**x) where n is 10 or 2 > and x is a decreasing series integer value until there is no effect. That > will tell you the resolution on the platform on which you're running... or > else you'll get an underflow error. :-\ > > Post your (readable) code and I'll run it on a few machines. The mantissa will be at least `perl -V:nv_preserves_uv_bits` bits. (nv_preserves_uv_bits will be the lesser of the number of bits in your unsigned integers and the mantissa of your floating point values.) (Most of this is out of perl's hands and dependent on your libc/math lib. There are problems with some versions of perl with converting a string to a floating point number that have been fixed, though.) (Anybody bored should check out Ilya's recent post to clpmoderated for the metaphor of the year (though unsuitable for Time magazine's cover)). From itayf at fhcrc.org Thu Oct 2 01:06:46 2003 From: itayf at fhcrc.org (Itay Furman) Date: Mon Aug 2 21:37:09 2004 Subject: SPUG: S.O.S: Sum-Of-Squares In-Reply-To: <20031001212718.A95044@beaver.net> Message-ID: Thanks to Doug and Yitzchak for their detailed and illuminating reply. I'd like to answer to their inquiries. On Wed, 1 Oct 2003, Doug Beaver wrote: > i'm curious, is it ever possible for the residue to be a value other > than 0? > No (in theory). On Wed, 1 Oct 2003, Yitzchak Scott-Thoennes wrote: > But I'm not sure what you are trying to accomplish-- x/(x**.5 * x**.5) > is supposed to always be one. Are you sure you don't mean to be > getting the ratio of the sum of squares to the square of the sum? > I thought it was suppose to be 1, too :-| Originally, I wanted to compute the deviation of the scalar product of two arbitrary normalized vectors v and u: 1 - (u dot v) / |u||v| I was surprised to find out that when u and v are incidentally identical I get a non-zero deviation. Naiively, I didn't expect a numerical flow in such a simple operation :-( After some experimenting I converged on the small script that I posted, that implements the above Eq for the special case that u=v. ( For those who follow up and need a reminder: if u = (u1, u2, ..., uN) and v = (v1, v2, ..., vN) then u dot v = u1*v1 + u2*v2 + ... uN*vN |u| = sqrt( u1**2 + u2**2 + ... + uN**2) |v| = sqrt( v1**2 + v2**2 + ... + vN**2). Therefore, if u is identical to v one should get 1 - (u dot v) / |u||v| = 1 - (u dot u)/|u||u| = 1 - 1 - 1 = 0 ) Thanks again for the guidance, Itay From MichaelRWolf at att.net Thu Oct 2 01:15:39 2003 From: MichaelRWolf at att.net (Michael R. Wolf) Date: Mon Aug 2 21:37:09 2004 Subject: SPUG: coding Win32 right-mouse actions in Perl Message-ID: How do you code the right-mouse events? I'm only really interested in "open" right now, but I figure that once I've got that, I'll have "print", too. This is part of a bigger project -- splitting my non-ASCII[1] email into various parts then letting my WinDOS laptop DWIM the pieces. Mostly, that will be running IE on them, since they're mostly HTML, but it *always* means doing the extension-specific "open" action. Pointers to doc's or a simple code frag would be great. I don't need nothin' elaborate. I've read a few FAQ's and Win32 modules, but don't seem to be digging in the right places. Point me in the right direction and I'll Read The Fine Manual. Thanks, Michael Wolf Notes: [1] I'd rather fight than switch, but I've been fighting a loosing battle on the ASCII-only email front. I'm having to devine the contents of HTML (and worse) email, and I'm getting tired of visually parsing HTML to do so. -- Michael R. Wolf All mammals learn by playing! MichaelRWolf@att.net From MichaelRWolf at att.net Thu Oct 2 02:25:35 2003 From: MichaelRWolf at att.net (Michael R. Wolf) Date: Mon Aug 2 21:37:09 2004 Subject: SPUG: assigning to $0; different Linuces In-Reply-To: <3F4EA658.3090801@cpan.org> (Jeremy G. Kahn's message of "Thu, 28 Aug 2003 18:03:20 -0700") References: <3F4EA658.3090801@cpan.org> <20030925101450.A11714@hobart.helvella.org> Message-ID: Jeremy G Kahn writes: > Has anybody else discovered that the ability to assign with $0 varies > across even Linux versions? Old thread. New information. I noticed that the 5.8.1 perldelta (http://www.hut.fi/~jhi/perldelta-5.8.1.html) mentioned that setting $0 works again on certain Linux versions (http://www.hut.fi/~jhi/perldelta-5.8.1.html#platformspecific_fixes). -- Michael R. Wolf All mammals learn by playing! MichaelRWolf@att.net From m3047 at inwa.net Thu Oct 2 11:18:32 2003 From: m3047 at inwa.net (Fred Morris) Date: Mon Aug 2 21:37:09 2004 Subject: SPUG: S.O.S: Sum-Of-Squares (nickname:Help) Message-ID: I suppose I should be nice and answer this question, even though it makes my head hurt. However, there's a fundamental lesson here that languages cannot solve thinking problems, and leaving that unanswered made my head continue to hurt. So, I sincerely hope that this explanation is useful. In a nutshell, there is no rational representation for the square root of 2. >The problem: for some cases I get a small, non-zero deviation. >My question: does any one have some insight or rules-of-a-thumb as to >the expected numerical precision in basic arithmetic operations under Perl? > >I should point out that I have found a simple workaround (see further below), >but would like some insight for future reference. > > Thanks, > Itay > >[...] >#!/usr/local/bin/perl -w BTW, Perl lives at /usr/bin/perl on all three of my test boxes. >use strict; >my @elem = @ARGV; # Elements of vector. >my $sos = 0; # Sum-Of-Squares >$sos += $_**2 foreach (@elem); >print "\t"x4, "sos=$sos\tresidue=", > 1-$sos/($sos**0.5 * $sos**0.5), "\n"; >exit; I get divide by zero on all platforms without any arguments. :-p >#### Some examples #### > >## OK >$ test_innerprod.pl 1 1 1 1 > sos=4 residue=0 >$ test_innerprod.pl 1 0 0 0 > sos=1 residue=0 >## Wrong ! >$ test_innerprod.pl 1 1 1 0 > sos=3 residue=-2.22044604925031e-16 >## Number of 1's doesn't matter, necessarily >$ test_innerprod.pl 1 1 0 0 > sos=2 residue=2.22044604925031e-16 >## Order doesn't matter >$ test_innerprod.pl 1 0 1 0 > sos=2 residue=2.22044604925031e-16 >## Length doesn't matter >$ test_innerprod.pl 1 1 0 > sos=2 residue=2.22044604925031e-16 >## OK >$ test_innerprod.pl 1 0 0 > sos=1 residue=0 >## Smallest vector that yields the flow >$ test_innerprod.pl 1 1 > sos=2 residue=2.22044604925031e-16 This should have been the clue: recast this statement as "simple scalars do not leave a residue." >## These don't have to be 1's >$ test_innerprod.pl 0.5 0.5 0 0 > sos=0.5 residue=2.22044604925031e-16 >$ test_innerprod.pl 0.5 0.5 > sos=0.5 residue=2.22044604925031e-16 > Without going exhaustively through all of these cases, I get the same values on SuSE 8.2/Perl 5.8, SuSE 6.4/Perl 5.5.3, Solaris (Sparc)/Perl 5.5.3. Earlier I observed that the residue was always the same. [3,3,3,1] (sos 28) is a case where it's not. Here's what's going on: Things which yield a rational (and representable) square root are reversible, and things which don't aren't. This is not surprising. (In fact, I'm more surprised that [.1,.1,.1,.1] doesn't leave a residue, since 1/10 is a repeating decimal in base 2. I'm sure if I thought about it long enough, I'd divine the reason.) >#### My workaround #### > >$ cat test_innerprod.pl >#!/usr/local/bin/perl -w >use strict; >my @elem = @ARGV; # Elements of vector. >my $sos = 0; # Sum-Of-Squares >$sos += $_**2 foreach (@elem); >print "\t"x4, "sos=$sos\tresidue=", > ################################################# > # Take the square-root AFTER making the product # > # Compare with previous version # > # 1-$sos/($sos**0.5 * $sos**0.5) # > ################################################# > 1-$sos/($sos*$sos)**0.5, "\n"; >exit; That's perfectly reasonable. As a general philosophy, it is best to assume that when you're trying to do "high-precision" math with floating points... you can't! The language is irrelevant. Languages (and implementations of languages) do vary in their handling of representational errors, but that's a different. A general practice is to round or floor at important points based on analysis of the algorithm (although refactoring is another valuable technique). Never assume that the result of a floating point calc is accurate to the limits of the mantissa; never represent as much, either. Analysis (and appropriate rounding/flooring) should allow you to assert that the result of the calc is accurate to some number of places. Flooring is often preferred to rounding because it can allow the direction of the error to be predicted better. (Just make sure you know the difference between "flooring" towards 0, and flooring towards -1*infinity.) HTH. -- Fred Morris m3047@inwa.net From matw at eclipse-optics.com Thu Oct 2 11:20:19 2003 From: matw at eclipse-optics.com (Mathew D. Watson) Date: Mon Aug 2 21:37:09 2004 Subject: SPUG: S.O.S: Sum-Of-Squares (nickname:Help) In-Reply-To: Message-ID: > -----Original Message----- > From: spug-list-bounces@mail.pm.org > [mailto:spug-list-bounces@mail.pm.org]On Behalf Of Itay Furman > Sent: Wednesday, October 01, 2003 4:05 PM > To: Seattle Perl Users Group > Subject: SPUG: S.O.S: Sum-Of-Squares (nickname:Help) > [snip] > $sos += $_**2 foreach (@elem); [snip] > 1-$sos/($sos**0.5 * $sos**0.5), "\n"; vs. > 1-$sos/($sos*$sos)**0.5, "\n"; I used to know this stuff cold, but here's the best I can do today. The two expressions are equivalent using real numbers, but with C doubles, order can be everything. Both Yitzchak and Fred have a pretty good handle on what's happening, but I want to make a couple of points and follow with a question. First point ... C double precision numbers can be exact for integer values up to a big number that I can't remember. The machine instructions for add and multiply _should_ preserve this property for operations whose result remains within the domain of integers with an exact double representation. One half (0.5) also has an exact double representation, and the same should be true regarding arithmetic operations. What I'm leading up to is that $sos itself should be (and probably is) exact given the test cases you used to exercise your code. Second point ... Here's where order matters. $sos**0.5 probably does not have an exact double representation, while $sos*$sos does. Thus you get a "reside" when you multiply $sos**0.5 with itself. Square rooting $sos*$sos probably results in an exact answer because $sos*$sos is an exact square, and the machine code for square root probably handles that correctly. So now I have a question for the PERL experts out there. Is there a way to _really_know_ what the bit pattern of $sos is? If there is, then we can bit by bit check our arithmetic. I've done this before in C, and what I recall is that printf() (print in Perl) should not be implicitly trusted. For example, print "1.0 = ", 1.0; results in the output "1.0 = 1", which is correct this time, but the author of print didn't guarantee this is always the case. What I'd like to see (and my Perl skills are too weak to do) is something like a 'bit capture' of $sos followed by bit ANDs with binary 1 followed by a bit shift all printed out within a loop (Yes, I trust the output of print 1;). My $0.02, --Mat From itayf at fhcrc.org Thu Oct 2 23:39:32 2003 From: itayf at fhcrc.org (Itay Furman) Date: Mon Aug 2 21:37:09 2004 Subject: SPUG: S.O.S: Sum-Of-Squares (nickname:Help) In-Reply-To: Message-ID: Thanks to Fred Morris and Mathew D. Watson for additional insight into this matter and for further suggestions. I was lulled by the relative ease of Perl programming into imagining that it will do everything for me -- possibly, including thinking ;-0 It was a bit painful to wake up; but a lesson was learned. Itay From sthoenna at efn.org Fri Oct 3 01:22:01 2003 From: sthoenna at efn.org (Yitzchak Scott-Thoennes) Date: Mon Aug 2 21:37:09 2004 Subject: SPUG: S.O.S: Sum-Of-Squares (nickname:Help) In-Reply-To: References: Message-ID: <20031003062201.GB2372@efn.org> On Thu, Oct 02, 2003 at 09:20:19AM -0700, "Mathew D. Watson" wrote: > So now I have a question for the PERL experts out there. Is there a way to > _really_know_ what the bit pattern of $sos is? If there is, then we can bit > by bit check our arithmetic. I've done this before in C, and what I recall > is that printf() (print in Perl) should not be implicitly trusted. For > example, print "1.0 = ", 1.0; results in the output "1.0 = 1", which is > correct this time, but the author of print didn't guarantee this is always > the case. What I'd like to see (and my Perl skills are too weak to do) is > something like a 'bit capture' of $sos followed by bit ANDs with binary 1 > followed by a bit shift all printed out within a loop (Yes, I trust the > output of print 1;). I didn't understand that last part; what is it that you want again?. He had a number not-quite-equal to 1 and subtracted it from 1. That left him with -(2**-52), so his original number was 1+2**-52, i.e. the next representable number after 1. So we know just the lowest bit of the [1] mantissa was wrong. (Fred said he had a case where the error was twice as large. That would be the second-lowest bit being wrong.) [1] http://wombat.doc.ic.ac.uk/foldoc/foldoc.cgi?query=mantissa From matw at eclipse-optics.com Sun Oct 5 11:03:56 2003 From: matw at eclipse-optics.com (Mathew D. Watson) Date: Mon Aug 2 21:37:09 2004 Subject: SPUG: The bit pattern of a number (was sum-of-squares) Message-ID: I would like to determine the bit pattern of a Perl floating point number. In C I would do something like: 1. start by assigning the address of a double to a pointer-to-char; 2. then I'd look at the char value (i.e. determine its bit pattern); 3. increment the char pointer; 4. repeat steps 2 & 3 until I've reached the end of the double. How do I do this in Perl? Maybe this is really simple, but I'm stumped. --Mat Mathew D. Watson, Ph.D. Eclipse Optics Corporation 10439 NE 28th Pl. Bellevue, WA 98004 425 827 0427 phn, 801 751 2369 fax matw@eclipse-optics.com From ben at reser.org Sun Oct 5 11:53:22 2003 From: ben at reser.org (Ben Reser) Date: Mon Aug 2 21:37:09 2004 Subject: SPUG: The bit pattern of a number (was sum-of-squares) In-Reply-To: References: Message-ID: <20031005165322.GX11795@titanium.brain.org> On Sun, Oct 05, 2003 at 09:03:56AM -0700, Mathew D. Watson wrote: > I would like to determine the bit pattern of a Perl floating point number. > In C I would do something like: > 1. start by assigning the address of a double to a pointer-to-char; > 2. then I'd look at the char value (i.e. determine its bit pattern); > 3. increment the char pointer; > 4. repeat steps 2 & 3 until I've reached the end of the double. > > How do I do this in Perl? Maybe this is really simple, but I'm stumped. I don't think you can. You can use pack but that won't really give you a reliable representation of how perl is storing it internally. Data::Dumper might be useful but it won't produce the data as binary output. Other than that I don't really have any suggestions, sorry. -- Ben Reser http://ben.reser.org "Conscience is the inner voice which warns us somebody may be looking." - H.L. Mencken From krahnj at acm.org Sun Oct 5 11:57:34 2003 From: krahnj at acm.org (John W. Krahn) Date: Mon Aug 2 21:37:10 2004 Subject: SPUG: The bit pattern of a number (was sum-of-squares) In-Reply-To: References: Message-ID: <03100509573500.26499@bng2406iy20tf> On Sunday 05 October 2003 09:03, Mathew D. Watson wrote: > I would like to determine the bit pattern of a Perl floating point > number. In C I would do something like: > 1. start by assigning the address of a double to a pointer-to-char; > 2. then I'd look at the char value (i.e. determine its bit pattern); > 3. increment the char pointer; > 4. repeat steps 2 & 3 until I've reached the end of the double. > > How do I do this in Perl? Maybe this is really simple, but I'm > stumped. $ perl -le'print scalar reverse unpack "b*", pack "d", 1' 0011111111110000000000000000000000000000000000000000000000000000 $ perl -le'print scalar reverse unpack "b*", pack "d", -1' 1011111111110000000000000000000000000000000000000000000000000000 $ perl -le'print scalar reverse unpack "b*", pack "d", 1e25' 0100010100100000100010110010101000101100001010000000001010010001 $ perl -le'print scalar reverse unpack "b*", pack "d", 1e-25' 0011101010111110111100101101000011110101110110100111110111011001 John -- use Perl; program fulfillment From tim at consultix-inc.com Sun Oct 5 12:53:23 2003 From: tim at consultix-inc.com (Tim Maher) Date: Mon Aug 2 21:37:10 2004 Subject: SPUG: Any grep's lack \b functionality? Message-ID: <20031005105323.A9959@timji.consultix-inc.com> In my upcoming book, I invest a lot of time pointing out the limitations of the original UNIX utilities, praising their GNU counterparts, and showing what Perl can do better than either of them. I know the original UNIX grep (and egrep) didn't have a "word-boundary" metacharacter, and I remember that was still true on at least some Unices (such as Solaris 2.5.1) by around 1996. But I don't really know the details of all the various contemporary Unices, as I only have access to Solaris 2.5.1 and 9. in my office. I'd like to think that all versions based on SVR4 would have identical utilities, but I know Sun likes to tweak things to "add value" (e.g., its Solaris 9.0 has not one but /two/ word-boundary enabled greps), and I've often been burned by finding that HP systems have the most archaic variations of whatever its competitors offer. So one question I'd like help answering is: 1) Is any fairly contemporary version of UNIX missing a grep, egrep, or sed that supports a word boundary metacharacter? (\b, \<, whatever) But the more general question that really interests me is: 2) Does anybody know where I can find a detailed list of the capabilities of each of the UNIX utilities (grep, sed, sort, tail, etc.) as they're provided by different Unices? TIA, -Tim *------------------------------------------------------------* | Tim Maher (206) 781-UNIX (866) DOC-PERL (866) DOC-UNIX | | tim(AT)Consultix-Inc.Com TeachMeUnix.Com TeachMePerl.Com | *+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-* | Watch for my Book: "Minimal Perl for Shell Programmers" | *------------------------------------------------------------* From ben at reser.org Sun Oct 5 12:51:20 2003 From: ben at reser.org (Ben Reser) Date: Mon Aug 2 21:37:10 2004 Subject: SPUG: The bit pattern of a number (was sum-of-squares) In-Reply-To: <03100509573500.26499@bng2406iy20tf> References: <03100509573500.26499@bng2406iy20tf> Message-ID: <20031005175120.GY11795@titanium.brain.org> On Sun, Oct 05, 2003 at 09:57:34AM -0700, John W. Krahn wrote: > $ perl -le'print scalar reverse unpack "b*", pack "d", 1' > 0011111111110000000000000000000000000000000000000000000000000000 > $ perl -le'print scalar reverse unpack "b*", pack "d", -1' > 1011111111110000000000000000000000000000000000000000000000000000 > $ perl -le'print scalar reverse unpack "b*", pack "d", 1e25' > 0100010100100000100010110010101000101100001010000000001010010001 > $ perl -le'print scalar reverse unpack "b*", pack "d", 1e-25' > 0011101010111110111100101101000011110101110110100111110111011001 pack/unpack doesen't return the internal representation, but rather the representation that you asked for via your format. I.E. This output may not match the output that perl actually was storing the data in. Which is what I think he was looking for. -- Ben Reser http://ben.reser.org "Conscience is the inner voice which warns us somebody may be looking." - H.L. Mencken From krahnj at acm.org Sun Oct 5 16:38:05 2003 From: krahnj at acm.org (John W. Krahn) Date: Mon Aug 2 21:37:10 2004 Subject: SPUG: The bit pattern of a number (was sum-of-squares) In-Reply-To: <20031005175120.GY11795@titanium.brain.org> References: <03100509573500.26499@bng2406iy20tf> <20031005175120.GY11795@titanium.brain.org> Message-ID: <03100514380501.26499@bng2406iy20tf> On Sunday 05 October 2003 10:51, Ben Reser wrote: > On Sun, Oct 05, 2003 at 09:57:34AM -0700, John W. Krahn wrote: > > $ perl -le'print scalar reverse unpack "b*", pack "d", 1' > > 0011111111110000000000000000000000000000000000000000000000000000 > > $ perl -le'print scalar reverse unpack "b*", pack "d", -1' > > 1011111111110000000000000000000000000000000000000000000000000000 > > $ perl -le'print scalar reverse unpack "b*", pack "d", 1e25' > > 0100010100100000100010110010101000101100001010000000001010010001 > > $ perl -le'print scalar reverse unpack "b*", pack "d", 1e-25' > > 0011101010111110111100101101000011110101110110100111110111011001 > > pack/unpack doesen't return the internal representation, but rather > the representation that you asked for via your format. I.E. This > output may not match the output that perl actually was storing the > data in. Which is what I think he was looking for. It does if you use the correct formats: $ perl -le'print unpack "B*", pack "S", 0b0001001000110100' 0011010000010010 That might be clearer using hexadecimal: $ perl -le'print unpack "H*", pack "S", 0x1234' 3412 Which shows the little-endian representation on my Intel compatable machine. John -- use Perl; program fulfillment From m3047 at inwa.net Sun Oct 5 18:22:51 2003 From: m3047 at inwa.net (Fred Morris) Date: Mon Aug 2 21:37:10 2004 Subject: SPUG: Coupling of closure parsing and compilation Message-ID: I was toying with the notion of using closures for the second part of a two-phase execution, but I'm not clear on the performance implications. What's going to happen is an object is going to do some setup, then there needs to be a handoff to something else, which needs to call back after it's done: (stuff happens..) $a->{b} = $b; $a->do_stuff(); $b->do_more_stuff(); package A; sub do_stuff() { my $self = shift; (stuff happens) $self->{b}->here_ya_go( sub { $self->finis(); } ); } sub finis() { ... } package B; sub here_ya_go() { my $self = shift; my $finis = shift; $self->{finis} = $finis; } sub do_more_stuff() { my $self = shift; (more stuff happens) &{$self->{finis}}(); (should I delete $self->{finis} here or am I just superstitious?) } There's more to it than that and I know that syntax is somewhat fractured, but hopefully it makes the intent clear. :-\ I've used them for fairly static purposes with good results (as subroutine arguments, for immediate execution). What I can't quite get clear in my mind is the coupling between the parsing of the Perl source and when the substitutions actually occur which produce the closure, and what effect this would have on performance both in terms of cpu and memory; the closures won't be particularly large chunks of code (although they'll call fairly large chunks of code). But they will be (re)created often. Is the source for the closure parsed with the rest of the chunk, or at the time that the closure is instantiated? Is the instantiated closure produced by (cloning if necessary, and then) substituting into the (parsed) opcode tree? What's the overhead of using a closure once and then throwing it away? Am I just asking for circular memory references here, given the OO "have you call me" scenario (bear in mind, the object(s) creating the closures won't be keeping handles to them, but they will be referencing themselves within the closures). Experience only, please. Pursuit of elegance is great, if it has a high expectation of success. -- Fred Morris m3047@inwa.net From matw at eclipse-optics.com Mon Oct 6 08:20:04 2003 From: matw at eclipse-optics.com (Mathew D. Watson) Date: Mon Aug 2 21:37:10 2004 Subject: SPUG: The bit pattern of a number (was sum-of-squares) In-Reply-To: <03100514380501.26499@bng2406iy20tf> Message-ID: Thanks folks! This looks perfect. --Mat > -----Original Message----- > From: spug-list-bounces@mail.pm.org > [mailto:spug-list-bounces@mail.pm.org]On Behalf Of John W. Krahn > Sent: Sunday, October 05, 2003 2:38 PM > To: SPUG List > Subject: Re: SPUG: The bit pattern of a number (was sum-of-squares) > > > On Sunday 05 October 2003 10:51, Ben Reser wrote: > > On Sun, Oct 05, 2003 at 09:57:34AM -0700, John W. Krahn wrote: > > > $ perl -le'print scalar reverse unpack "b*", pack "d", 1' > > > 0011111111110000000000000000000000000000000000000000000000000000 > > > $ perl -le'print scalar reverse unpack "b*", pack "d", -1' > > > 1011111111110000000000000000000000000000000000000000000000000000 > > > $ perl -le'print scalar reverse unpack "b*", pack "d", 1e25' > > > 0100010100100000100010110010101000101100001010000000001010010001 > > > $ perl -le'print scalar reverse unpack "b*", pack "d", 1e-25' > > > 0011101010111110111100101101000011110101110110100111110111011001 > > > > pack/unpack doesen't return the internal representation, but rather > > the representation that you asked for via your format. I.E. This > > output may not match the output that perl actually was storing the > > data in. Which is what I think he was looking for. > > It does if you use the correct formats: > > $ perl -le'print unpack "B*", pack "S", 0b0001001000110100' > 0011010000010010 > > That might be clearer using hexadecimal: > > $ perl -le'print unpack "H*", pack "S", 0x1234' > 3412 > > Which shows the little-endian representation on my Intel compatable > machine. > > > John > -- > use Perl; > program > fulfillment > > _____________________________________________________________ > Seattle Perl Users Group Mailing List > POST TO: spug-list@mail.pm.org http://spugwiki.perlocity.org > ACCOUNT CONFIG: http://mail.pm.org/mailman/listinfo/spug-list > MEETINGS: 3rd Tuesdays, U-District, Seattle WA > WEB PAGE: http://www.seattleperl.org > > From christopher.w.cantrall at boeing.com Mon Oct 6 10:18:45 2003 From: christopher.w.cantrall at boeing.com (Cantrall, Christopher W) Date: Mon Aug 2 21:37:10 2004 Subject: SPUG: Any grep's lack \b functionality? Message-ID: Boeing's install of AIX 4.3 has grep, egrep, fgrep, and ogrep. ogrep has no man page, but the usage is similar to other greps. fgrep has a "-w" word search flag, but there appears to be no true word boundary functionality. So on this AIX, there is no \b available. Good luck with the book. ____________________________________________ Chris Cantrall Structural Engineer, 777 Fuselage, Boeing Christopher.W.Cantrall@Boeing.com chris@cantrall.org http://perlmonks.org/index.pl?node=Louis_Wu -----Original Message----- From: Tim Maher [mailto:tim@consultix-inc.com] Sent: Sunday, October 05, 2003 10:53 AM To: spug-list@pm.org Subject: SPUG: Any grep's lack \b functionality? [snip] So one question I'd like help answering is: 1) Is any fairly contemporary version of UNIX missing a grep, egrep, or sed that supports a word boundary metacharacter? (\b, \<, whatever) But the more general question that really interests me is: 2) Does anybody know where I can find a detailed list of the capabilities of each of the UNIX utilities (grep, sed, sort, tail, etc.) as they're provided by different Unices? TIA, -Tim *------------------------------------------------------------* | Tim Maher (206) 781-UNIX (866) DOC-PERL (866) DOC-UNIX | | tim(AT)Consultix-Inc.Com TeachMeUnix.Com TeachMePerl.Com | *+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-* | Watch for my Book: "Minimal Perl for Shell Programmers" | *------------------------------------------------------------* From christopher.w.cantrall at boeing.com Mon Oct 6 12:54:39 2003 From: christopher.w.cantrall at boeing.com (Cantrall, Christopher W) Date: Mon Aug 2 21:37:10 2004 Subject: SPUG: Any grep's lack \b functionality? Message-ID: Tim wrote: > I take it you're saying that grep and egrep are missing \< and \b? > AFAIK, that means your AIX isn't "UNIX98 compliant". Hmm... I couldn't find those meta-characters in the man page, and they didn't do anything in my command line tests, so I guess I am saying that AIX 4.3 (as Boeing installs it) is missing any word-boundary metacharacter I'm familiar with. The greps I've referenced all had the standard Files listed at the end of the man page, and didn't have any of the usual Boeing disclaimers I've seen with our more custom stuff. OTOH, our Perl install is "version 5.005_03 built for aix-thread", so we might not have the latest versions of anything. > > Boeing's install of AIX 4.3 has grep, egrep, fgrep, and ogrep. > > ogrep has no man page, but the usage is similar to other greps. > > Sounds like an "old" grep; if sufficiently old, it mighit not > even have -i. Here's the output of "ogrep" at the command line: Usage: ogrep [-E|-F] [-c|-l|-q] [-insvxbhwy] [-p[parasep]] -e pattern_list... [-f pattern_file...] [file...] Usage: ogrep [-E|-F] [-c|-l|-q] [-insvxbhwy] [-p[parasep]] [-e pattern_list...] -f pattern_file... [file...] Usage: ogrep [-E|-F] [-c|-l|-q] [-insvxbhwy] [-p[parasep]] pattern_list [file...] HTH. ____________________________________________ Chris Cantrall Structural Engineer, 777 Fuselage, Boeing Christopher.W.Cantrall@Boeing.com chris@cantrall.org http://perlmonks.org/index.pl?node=Louis_Wu > -----Original Message----- > From: Tim Maher/CONSULTIX [mailto:tim@teachmeperl.com] > Sent: Monday, October 06, 2003 10:00 AM > To: Cantrall, Christopher W > Cc: Tim Maher; spug-list@pm.org > Subject: Re: SPUG: Any grep's lack \b functionality? > > > On Mon, Oct 06, 2003 at 08:18:45AM -0700, Cantrall, > Christopher W wrote: > > Boeing's install of AIX 4.3 has grep, egrep, fgrep, and ogrep. > > ogrep has no man page, but the usage is similar to other greps. > > Sounds like an "old" grep; if sufficiently old, it mighit not > even have -i. > > > fgrep has a "-w" word search flag, but there appears to be no > > true word boundary functionality. So on this AIX, there is no > > \b available. > > I take it you're saying that grep and egrep are missing \< and \b? > AFAIK, that means your AIX isn't "UNIX98 compliant". Hmm... > > Tim > > > > Good luck with the book. > > Thanks! > > > > > ____________________________________________ > > Chris Cantrall > > Structural Engineer, 777 Fuselage, Boeing > > Christopher.W.Cantrall@Boeing.com > > chris@cantrall.org > > http://perlmonks.org/index.pl?node=Louis_Wu > > > > > > > > > > -----Original Message----- > > From: Tim Maher [mailto:tim@consultix-inc.com] > > Sent: Sunday, October 05, 2003 10:53 AM > > To: spug-list@pm.org > > Subject: SPUG: Any grep's lack \b functionality? > > > > [snip] > > > > So one question I'd like help answering is: > > > > 1) Is any fairly contemporary version of UNIX missing a grep, > > egrep, or sed that supports a word boundary metacharacter? > > (\b, \<, whatever) > > > > But the more general question that really interests me is: > > > > 2) Does anybody know where I can find a detailed list of the > > capabilities of each of the UNIX utilities (grep, sed, sort, > > tail, etc.) as they're provided by different Unices? > > > > TIA, > > > > -Tim > > *------------------------------------------------------------* > > | Tim Maher (206) 781-UNIX (866) DOC-PERL (866) DOC-UNIX | > > | tim(AT)Consultix-Inc.Com TeachMeUnix.Com TeachMePerl.Com | > > *+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-* > > | Watch for my Book: "Minimal Perl for Shell Programmers" | > > *------------------------------------------------------------* > > -- > > -Tim > *------------------------------------------------------------* > | Tim Maher (206) 781-UNIX (866) DOC-PERL (866) DOC-UNIX | > | tim(AT)Consultix-Inc.Com TeachMeUnix.Com TeachMePerl.Com | > *+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-* > | Watch for my Book: "Minimal Perl for Shell Programmers" | > *------------------------------------------------------------* > From sthoenna at efn.org Tue Oct 7 13:30:50 2003 From: sthoenna at efn.org (Yitzchak Scott-Thoennes) Date: Mon Aug 2 21:37:10 2004 Subject: SPUG: Coupling of closure parsing and compilation In-Reply-To: References: Message-ID: <20031007183049.GA400@efn.org> On Sun, Oct 05, 2003 at 04:22:51PM -0700, Fred Morris wrote: > I was toying with the notion of using closures for the second part of a > two-phase execution, but I'm not clear on the performance implications. > What's going to happen is an object is going to do some setup, then there > needs to be a handoff to something else, which needs to call back after > it's done: It looks to me as if you have some encapsulation problems. Perhaps you want a is-a b instead of a has-a b. Or perhaps you want to get rid of here_ya_go and have a $a->do_more_stuff that calls $b->do_more_stuff and $a->finis? Or perhaps you know you are violating the encasulation but are trying to do it in a clean and documented manner. It's hard to tell when you've abstracted the example down to just syntax rather than semantics. > &{$self->{finis}}(); > > (should I delete $self->{finis} here or am I just superstitious?) Since $b->{finis} will hold a refcnt on $a, you probably want to clear it when done with it to get orderly destruction. Or something like this ought to work: weaken(my $weak_self=$self)); $self->{b}->here_ya_go( sub { defined($weak_self) or return; $weak_self->finis(); } ); > What I can't quite get clear in my mind is the coupling between the parsing > of the Perl source and when the substitutions actually occur which produce > the closure, and what effect this would have on performance both in terms > of cpu and memory; the closures won't be particularly large chunks of code > (although they'll call fairly large chunks of code). But they will be > (re)created often. > > Is the source for the closure parsed with the rest of the chunk, or at the > time that the closure is instantiated? > > Is the instantiated closure produced by (cloning if necessary, and then) > substituting into the (parsed) opcode tree? > > What's the overhead of using a closure once and then throwing it away? In simple (hence inaccurate) terms, a coderef has two parts, the optree and the pad. The binding that makes it a closure lives in the pad and is generated at run-time when you hit the sub {} statement. The optree, OTOH, is generated from the sub {} body at compile-time. The overhead is low. > Am I just asking for circular memory references here, given the OO "have > you call me" scenario (bear in mind, the object(s) creating the closures > won't be keeping handles to them, but they will be referencing themselves > within the closures). Yes, but see above. > Experience only, please. Pursuit of elegance is great, if it has a high > expectation of success. Whoops. Ignore my first few elegance-pursuing sentences. From MichaelRWolf at att.net Wed Oct 8 15:04:42 2003 From: MichaelRWolf at att.net (Michael R. Wolf) Date: Mon Aug 2 21:37:10 2004 Subject: SPUG: scalar swap challenge Message-ID: I sent the following to MJD for use as a possible QOTW, then decided to share it wit SPUG first. Enjoy, Michael If you post an answer, please put "SPOILER" in the subject line. If you post an answer, please put "SPOILER" in the subject line. If you post an answer, please put "SPOILER" in the subject line. If you post an answer, please put "SPOILER" in the subject line. If you post an answer, please put "SPOILER" in the subject line. If you post an answer, please put "SPOILER" in the subject line. If you post an answer, please put "SPOILER" in the subject line. If you post an answer, please put "SPOILER" in the subject line. If you post an answer, please put "SPOILER" in the subject line. If you post an answer, please put "SPOILER" in the subject line. If you post an answer, please put "SPOILER" in the subject line. swap challenge> In most languages, values cannot be directly swapped without a swap challenge> temporary variable. It's a classic problem shared by passing trains, swap challenge> elevator passengers, and virtual memory systems. swap challenge> swap challenge> A swap code fragment typically looks like this. swap challenge> swap challenge> $temp = $left; swap challenge> $right = $left; swap challenge> $left = $temp; swap challenge> swap challenge> Perl's list assignment can do this directly. swap challenge> swap challenge> ($left, $right) = ($right, $left); swap challenge> swap challenge> Recently, I got challenged to do a swap without a temporary variable swap challenge> in C by someone who claimed it's always possible. Actually, it's swap challenge> always possible for *integral* types. Because I no longer enjoy coding swap challenge> in C, I reworded it to be a Perl challenge: swap challenge> swap challenge> swap two integral scalars without using a temporary scalar and swap challenge> without using the list assignment swapping idiom. Here's a little test script I put together to test my solution *after* I'd proven it on paper. #! /usr/bin/perl -w use warnings; use strict; my $iterations = shift @ARGV || 10; for (my $i = 0; $i < $iterations; $i++) { my ($orig_a, $a) = (int(rand 1000)) x 2; my ($orig_b, $b) = (int(rand 1000)) x 2; # Your $a/$b swap code goes here. $a = "something"; $b = "something"; printf("%4d %4d %s\n" => $a, $b, $a == $orig_b && $b == $orig_a ? "passed" : "failed: a was $orig_a, b was $orig_b"); } -- Michael R. Wolf All mammals learn by playing! MichaelRWolf@att.net From krahnj at acm.org Wed Oct 8 15:35:44 2003 From: krahnj at acm.org (John W. Krahn) Date: Mon Aug 2 21:37:10 2004 Subject: SPUG: scalar swap challenge In-Reply-To: References: Message-ID: <03100813354400.10955@bng2406iy20tf> On Wednesday 08 October 2003 13:04, Michael R. Wolf wrote: > > swap challenge> In most languages, values cannot be directly swapped > without a swap challenge> temporary variable. It's a classic problem > shared by passing trains, swap challenge> elevator passengers, and > virtual memory systems. swap challenge> > swap challenge> A swap code fragment typically looks like this. > swap challenge> > swap challenge> $temp = $left; > swap challenge> $right = $left; > swap challenge> $left = $temp; > swap challenge> > swap challenge> Perl's list assignment can do this directly. > swap challenge> > swap challenge> ($left, $right) = ($right, $left); > swap challenge> > swap challenge> Recently, I got challenged to do a swap without a > temporary variable swap challenge> in C by someone who claimed it's > always possible. Actually, it's swap challenge> always possible for > *integral* types. Because I no longer enjoy coding swap challenge> in > C, I reworded it to be a Perl challenge: > swap challenge> > swap challenge> swap two integral scalars without using a > temporary scalar and swap challenge> without using the list > assignment swapping idiom. It is pretty easy in perl: $ perl -le' my ( $x, $y ) = ( 32, 765 ); print "$x $y"; $x ^= $y; $y ^= $x; $x ^= $y; print "$x $y"; ( $x, $y ) = qw( six seven ); print "$x $y"; $x ^= $y; $y ^= $x; $x ^= $y; print "$x $y"; ' 32 765 765 32 six seven seven six :-) John -- use Perl; program fulfillment From krahnj at acm.org Wed Oct 8 15:35:44 2003 From: krahnj at acm.org (John W. Krahn) Date: Mon Aug 2 21:37:10 2004 Subject: SPUG: scalar swap challenge In-Reply-To: References: Message-ID: <03100813354400.10955@bng2406iy20tf> On Wednesday 08 October 2003 13:04, Michael R. Wolf wrote: > > swap challenge> In most languages, values cannot be directly swapped > without a swap challenge> temporary variable. It's a classic problem > shared by passing trains, swap challenge> elevator passengers, and > virtual memory systems. swap challenge> > swap challenge> A swap code fragment typically looks like this. > swap challenge> > swap challenge> $temp = $left; > swap challenge> $right = $left; > swap challenge> $left = $temp; > swap challenge> > swap challenge> Perl's list assignment can do this directly. > swap challenge> > swap challenge> ($left, $right) = ($right, $left); > swap challenge> > swap challenge> Recently, I got challenged to do a swap without a > temporary variable swap challenge> in C by someone who claimed it's > always possible. Actually, it's swap challenge> always possible for > *integral* types. Because I no longer enjoy coding swap challenge> in > C, I reworded it to be a Perl challenge: > swap challenge> > swap challenge> swap two integral scalars without using a > temporary scalar and swap challenge> without using the list > assignment swapping idiom. It is pretty easy in perl: $ perl -le' my ( $x, $y ) = ( 32, 765 ); print "$x $y"; $x ^= $y; $y ^= $x; $x ^= $y; print "$x $y"; ( $x, $y ) = qw( six seven ); print "$x $y"; $x ^= $y; $y ^= $x; $x ^= $y; print "$x $y"; ' 32 765 765 32 six seven seven six :-) John -- use Perl; program fulfillment From sthoenna at efn.org Wed Oct 8 15:50:07 2003 From: sthoenna at efn.org (Yitzchak Scott-Thoennes) Date: Mon Aug 2 21:37:10 2004 Subject: SPUG: scalar swap challenge [semi-SPOILER] In-Reply-To: References: Message-ID: <20031008205007.GA2936@efn.org> On Wed, Oct 08, 2003 at 01:04:42PM -0700, "Michael R. Wolf" wrote: > my $iterations = shift @ARGV || 10; > > for (my $i = 0; $i < $iterations; $i++) { > my ($orig_a, $a) = (int(rand 1000)) x 2; > my ($orig_b, $b) = (int(rand 1000)) x 2; > > # Your $a/$b swap code goes here. > $a = "something"; > $b = "something"; > > printf("%4d %4d %s\n" => > $a, $b, > $a == $orig_b && $b == $orig_a ? "passed" : "failed: a was $orig_a, b was $orig_b"); > } Just a comment on the test script: Because perl will silently shift from integers to floating point where necessary, such swap code may have a flaw that this test won't exercise, at least where NVs don't preserve all the bits of an IV. Just increasing the 1000 to 2**63 won't help, since I think that a single int(rand()) sequence will end up only producing integers that are representable in floating point. I don't think this problem is solvable in perl without some limitation on what kind of integers are input. (This kind of problem is why you should try to have perl use long doubles when using long longs. Unfortunately, many platforms have adequate support for one but not the other.) From legrady at earthlink.net Wed Oct 8 15:59:55 2003 From: legrady at earthlink.net (Tom Legrady) Date: Mon Aug 2 21:37:10 2004 Subject: SPOILER Re: SPUG: scalar swap challenge Message-ID: <22276559.1065646795054.JavaMail.root@thecount.psp.pas.earthlink.net> # Your $a/$b swap code goes here. $a ^= $b; $b ^= $a; $a ^= $b; Tom Legrady From spug-list at l.ifokr.org Wed Oct 8 16:14:47 2003 From: spug-list at l.ifokr.org (Brian Hatch) Date: Mon Aug 2 21:37:10 2004 Subject: SPUG: scalar swap challenge In-Reply-To: References: Message-ID: <20031008211447.GX27401@ifokr.org> > swap challenge> A swap code fragment typically looks like this. > swap challenge> > swap challenge> $temp = $left; > swap challenge> $right = $left; > swap challenge> $left = $temp; I think many of us will know the trick you're thinking of. However the fact is that a temporary variable will be faster (three assignments vs three mathematical operations). -- Brian Hatch The Theorem Theorem: Systems and Security Engineer If If, Then Then. http://www.ifokr.org/bri/ Every message PGP signed -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://mail.pm.org/pipermail/spug-list/attachments/20031008/59a24aaf/attachment.bin From devnull at devnullsoftware.com Wed Oct 8 16:47:38 2003 From: devnull at devnullsoftware.com (Lee Wilson) Date: Mon Aug 2 21:37:10 2004 Subject: SPOILER Re: SPUG: scalar swap challenge In-Reply-To: <22276559.1065646795054.JavaMail.root@thecount.psp.pas.earthlink.net> Message-ID: Sheesh, I sent this earlier, but I think I sent it to an individual rather than the list. Doh =) One of my favorite interview questions is to ask what this code does. Assume A and B are of int type. B=(A/2+A/2+(A%2==1?1:0))+(A=B)-B; This line can reduce to: B = A + (A=B) - B; Answer: it swaps A and B without using a temp var, and in one line of code. I think this second line would work in perl for any scalar type, actually (assuming you put $A and $B =) ). On Wed, 8 Oct 2003, Tom Legrady wrote: > # Your $a/$b swap code goes here. > $a ^= $b; > $b ^= $a; > $a ^= $b; ============================================================================== Lee Wilson - INTP http://www.devnullsoftware.com Software Developer / RealNetworks http://www.realarcade.com Home:425-895-9868 Cell:425-890-5463 Office: 206-892-6410 ============================================================================== There are 10 kinds of people in the world: the people who understand ternary, the people who dont, but care, and the people who don't understand or care. ============================================================================== From creede at penguinsinthenight.com Wed Oct 8 17:51:49 2003 From: creede at penguinsinthenight.com (Creede Lambard) Date: Mon Aug 2 21:37:10 2004 Subject: SPUG: Re: scalar swap challenge (SPOILER!) In-Reply-To: References: <22276559.1065646795054.JavaMail.root@thecount.psp.pas.earthlink.net> Message-ID: <20031008225149.GB13988@igor.penguinsinthenight.com> I think I sent my entry directly to Michael . . . my @stack; unshift @stack, $a; unshift @stack, $b; $a = shift @stack; $b = shift @stack; Note that this will work with any scalar, not just integers. Note that it also uses temporary storage, but not a temporary scalar. So far I think I like the approach using ^= best. From cmeyer at helvella.org Wed Oct 8 18:30:07 2003 From: cmeyer at helvella.org (Colin Meyer) Date: Mon Aug 2 21:37:10 2004 Subject: SPUG: Re: scalar swap challenge (SPOILER!) In-Reply-To: <20031008225149.GB13988@igor.penguinsinthenight.com>; from creede@penguinsinthenight.com on Wed, Oct 08, 2003 at 03:51:49PM -0700 References: <22276559.1065646795054.JavaMail.root@thecount.psp.pas.earthlink.net> <20031008225149.GB13988@igor.penguinsinthenight.com> Message-ID: <20031008163007.B16259@hobart.helvella.org> On Wed, Oct 08, 2003 at 03:51:49PM -0700, Creede Lambard wrote: > I think I sent my entry directly to Michael . . . > > my @stack; > > unshift @stack, $a; > unshift @stack, $b; > $a = shift @stack; > $b = shift @stack; > > Note that this will work with any scalar, not just integers. Note that > it also uses temporary storage, but not a temporary scalar. The ^= solution occurred immediatly to me, because I had seen the c language variety of this puzzler before. But I like your solution, because it shows that you read the puzzle more thoroughly than me. ;-) -Colin. From ced at carios2.ca.boeing.com Wed Oct 8 18:55:17 2003 From: ced at carios2.ca.boeing.com (ced@carios2.ca.boeing.com) Date: Mon Aug 2 21:37:10 2004 Subject: SPUG: Re: scalar swap challenge (SPOILER!) Message-ID: <200310082355.QAA23116@carios2.ca.boeing.com> > my @stack; > unshift @stack, $a; > unshift @stack, $b; > $a = shift @stack; > $b = shift @stack; Cool... a slight variant: push @ARGV,$y,$x; ($y,$x)=(pop,pop); -- Charles DeRykus From creede at penguinsinthenight.com Wed Oct 8 20:40:36 2003 From: creede at penguinsinthenight.com (Creede Lambard) Date: Mon Aug 2 21:37:10 2004 Subject: SPUG: Re: scalar swap challenge (SPOILER!) In-Reply-To: <200310082355.QAA23116@carios2.ca.boeing.com> References: <200310082355.QAA23116@carios2.ca.boeing.com> Message-ID: <20031009014036.GD13988@igor.penguinsinthenight.com> On Wed, Oct 08, 2003 at 04:55:17PM -0700, ced@carios2.ca.boeing.com wrote: > > push @ARGV,$y,$x; > ($y,$x)=(pop,pop); > Shouldn't that be push @_, $y, $x; ($y, $x) = (pop, pop); ? You could also do $ENV{FOO} = $x; $ENV{BAR} = $y; $y = $ENV{FOO}; $x = $ENV{BAR}; and then start an argument over whether environment variables count as scalars. :) (I know, that's pushing it big time) A mail from Michael a few minutes ago informed me that he was trying to eschew temporary storage of any kind, so I'm trying to think outside that particular box. From krahnj at acm.org Wed Oct 8 15:35:44 2003 From: krahnj at acm.org (John W. Krahn) Date: Mon Aug 2 21:37:10 2004 Subject: SPUG: scalar swap challenge In-Reply-To: References: Message-ID: <03100813354400.10955@bng2406iy20tf> On Wednesday 08 October 2003 13:04, Michael R. Wolf wrote: > > swap challenge> In most languages, values cannot be directly swapped > without a swap challenge> temporary variable. It's a classic problem > shared by passing trains, swap challenge> elevator passengers, and > virtual memory systems. swap challenge> > swap challenge> A swap code fragment typically looks like this. > swap challenge> > swap challenge> $temp = $left; > swap challenge> $right = $left; > swap challenge> $left = $temp; > swap challenge> > swap challenge> Perl's list assignment can do this directly. > swap challenge> > swap challenge> ($left, $right) = ($right, $left); > swap challenge> > swap challenge> Recently, I got challenged to do a swap without a > temporary variable swap challenge> in C by someone who claimed it's > always possible. Actually, it's swap challenge> always possible for > *integral* types. Because I no longer enjoy coding swap challenge> in > C, I reworded it to be a Perl challenge: > swap challenge> > swap challenge> swap two integral scalars without using a > temporary scalar and swap challenge> without using the list > assignment swapping idiom. It is pretty easy in perl: $ perl -le' my ( $x, $y ) = ( 32, 765 ); print "$x $y"; $x ^= $y; $y ^= $x; $x ^= $y; print "$x $y"; ( $x, $y ) = qw( six seven ); print "$x $y"; $x ^= $y; $y ^= $x; $x ^= $y; print "$x $y"; ' 32 765 765 32 six seven seven six :-) John -- use Perl; program fulfillment From cmeyer at helvella.org Thu Oct 9 12:43:33 2003 From: cmeyer at helvella.org (Colin Meyer) Date: Mon Aug 2 21:37:10 2004 Subject: SPOILER Re: SPUG: scalar swap challenge In-Reply-To: <22276559.1065646795054.JavaMail.root@thecount.psp.pas.earthlink.net>; from legrady@earthlink.net on Wed, Oct 08, 2003 at 01:59:55PM -0700 References: <22276559.1065646795054.JavaMail.root@thecount.psp.pas.earthlink.net> Message-ID: <20031009104333.E18947@hobart.helvella.org> Here's a Perlish solution. Because of Perl's automatic coercion of data types, it works with strings, integers or floats. It won't work with references, but it would *appear* to work for objects with stringification overloaded. ;-) #!/usr/bin/perl $a = 'one'; $b = 'two'; print "$a $b\n"; $a .= $b; $b = substr $a, 0, length($a) - length($b); $a = substr $a, length($b), length($a); print "$a $b\n"; __END__ Have fun, -Colin. From cmeyer at helvella.org Thu Oct 9 13:39:53 2003 From: cmeyer at helvella.org (Colin Meyer) Date: Mon Aug 2 21:37:10 2004 Subject: SPOILER Re: SPUG: scalar swap challenge In-Reply-To: <20031009111944.A29512@timji.consultix-inc.com>; from tim@teachmeperl.com on Thu, Oct 09, 2003 at 11:19:44AM -0700 References: <22276559.1065646795054.JavaMail.root@thecount.psp.pas.earthlink.net> <20031009104333.E18947@hobart.helvella.org> <20031009111944.A29512@timji.consultix-inc.com> Message-ID: <20031009113953.F18947@hobart.helvella.org> On Thu, Oct 09, 2003 at 11:19:44AM -0700, Tim Maher/CONSULTIX wrote: > On Thu, Oct 09, 2003 at 10:43:33AM -0700, Colin Meyer wrote: > > I was also thinking tangentially, considering a regex-based > solution. But really, what's the point here? WHY is it desirable > to avoid using a temporary variable? Presumably to minimize memory > usage, because making a fresh entry in the symbol table alone surely > couldn't be motivating the stinginess indicated by the goal. (But > the guy who was motivated to save that extra variable allocation > must be using computers from the 80s, for this to be a practical concern; > unless we're talking about storing all the digits of PI in one of the > scalars that needs swapping). > > And given that most solutions based on string handling would tend to > require some additional memory usage (although I'd like to think > the substring case would be an exception), I'm left asking why not just spend > the extra scalar, and do the conventional swap? If the intent of the > question is merely to showcase different approaches, fine, but ones > that use even more resources than the obvious variable-juggling one > don't seem worthy of much free publicity. I don't think there is any reason to not use a temporary variable, especially considering the obfuscation factor. It is much more clear to use a temp var. Unlike Lee, who likes to interview programmers with an especially convoluted variety of this thing, I'd give a stern talking to any programmer who I caught doing silly things like this. If I caught them doing unnecessary obfuscation a second time, I'd fire them. After all, programmers are a dime a dozen; they'd better behave! ;-) Actually, I quite enjoy interviews with silly puzzles. I assume that Lee would eschew this sort of thing in real code. It is fun (and probably good brain exercise) to think about code puzzles, and play with them *in a non production context*. I'm curious about what MJD's response about using this as one of his weekly quizzes would be. I don't follow them too closely, but I think that he tends to favor practical solutions, whereas this puzzle is geared towards entirely unpractical solutions. -Colin. From devnull at devnullsoftware.com Thu Oct 9 13:36:17 2003 From: devnull at devnullsoftware.com (Lee Wilson) Date: Mon Aug 2 21:37:10 2004 Subject: SPOILER Re: SPUG: scalar swap challenge In-Reply-To: <20031009113953.F18947@hobart.helvella.org> Message-ID: On Thu, 9 Oct 2003, Colin Meyer wrote: > Actually, I quite enjoy interviews with silly puzzles. I assume that > Lee would eschew this sort of thing in real code. It is fun (and > probably good brain exercise) to think about code puzzles, and play > with them *in a non production context*. If I actually saw someone programming something my example in production code, I would be annoyed because it's not at all readable or clear what it's doing. In fact, it's pretty ugly code =) I would then try to figure out what it's doing, rewrite it to be readable (even if the new way might be slightly less efficient - code readability is, in most cases, more important than a saved instruction cycle or two), and go talk to the original coder (if they were still around). Probably in that order =) The reason I ask the question in interviews is to see how the person's brain works - not necessarily if they're smart, but more how they go about solving a problem where the answer is not immediately obvious. Other questions I ask tend to be much more practical: given a database schema, give SQL to find various bits of info; grok this section of code and tell me what the output will be; code a function to look up an element in a multi-bucket hash; program a function to give the maximum depth of a binary tree; write a perl sub that accepts as input a string, 2 scalars, an array, a hash, a filehandle, and a string, then write the calling line; etc. The obfuscated code sample I showed here is more of a "fun" question, in all honesty (as you suspected). ============================================================================== Lee Wilson - INTP http://www.devnullsoftware.com Software Developer / RealNetworks http://www.realarcade.com Home:425-895-9868 Cell:425-890-5463 Office: 206-892-6410 ============================================================================== There are 10 kinds of people in the world: the people who understand ternary, the people who dont, but care, and the people who don't understand or care. ============================================================================== From krahnj at acm.org Wed Oct 8 15:35:44 2003 From: krahnj at acm.org (John W. Krahn) Date: Mon Aug 2 21:37:10 2004 Subject: SPUG: scalar swap challenge In-Reply-To: References: Message-ID: <03100813354400.10955@bng2406iy20tf> On Wednesday 08 October 2003 13:04, Michael R. Wolf wrote: > > swap challenge> In most languages, values cannot be directly swapped > without a swap challenge> temporary variable. It's a classic problem > shared by passing trains, swap challenge> elevator passengers, and > virtual memory systems. swap challenge> > swap challenge> A swap code fragment typically looks like this. > swap challenge> > swap challenge> $temp = $left; > swap challenge> $right = $left; > swap challenge> $left = $temp; > swap challenge> > swap challenge> Perl's list assignment can do this directly. > swap challenge> > swap challenge> ($left, $right) = ($right, $left); > swap challenge> > swap challenge> Recently, I got challenged to do a swap without a > temporary variable swap challenge> in C by someone who claimed it's > always possible. Actually, it's swap challenge> always possible for > *integral* types. Because I no longer enjoy coding swap challenge> in > C, I reworded it to be a Perl challenge: > swap challenge> > swap challenge> swap two integral scalars without using a > temporary scalar and swap challenge> without using the list > assignment swapping idiom. It is pretty easy in perl: $ perl -le' my ( $x, $y ) = ( 32, 765 ); print "$x $y"; $x ^= $y; $y ^= $x; $x ^= $y; print "$x $y"; ( $x, $y ) = qw( six seven ); print "$x $y"; $x ^= $y; $y ^= $x; $x ^= $y; print "$x $y"; ' 32 765 765 32 six seven seven six :-) John -- use Perl; program fulfillment From MichaelRWolf at att.net Thu Oct 9 17:03:17 2003 From: MichaelRWolf at att.net (Michael R. Wolf) Date: Mon Aug 2 21:37:10 2004 Subject: SPUG: 5-10 day Java->C#.Net gig Message-ID: I'm multi-lingual, but this opportunity is not for me. Is it you? The company is moving an existing application from Java (Java Web Start experience would be great!) to C#.Net, and needs someone who's already well up to speed on Java tweak it and help the C# folks to port it. If you're interested, I'd be glad to connect you. Michael Wolf 206/782-8377 -- Michael R. Wolf All mammals learn by playing! MichaelRWolf@att.net From MichaelRWolf at att.net Thu Oct 9 17:52:50 2003 From: MichaelRWolf at att.net (Michael R. Wolf) Date: Mon Aug 2 21:37:10 2004 Subject: SPUG: Re: scalar swap challenge (SPOILER!) In-Reply-To: <20031009014036.GD13988@igor.penguinsinthenight.com> (Creede Lambard's message of "Wed, 8 Oct 2003 18:40:36 -0700") References: <200310082355.QAA23116@carios2.ca.boeing.com> <20031009014036.GD13988@igor.penguinsinthenight.com> Message-ID: Creede Lambard writes: [...] push @_, $y, $x; ($y, $x) = (pop, pop); [...] > $ENV{FOO} = $x; > $ENV{BAR} = $y; > $y = $ENV{FOO}; > $x = $ENV{BAR}; [...] > A mail from Michael a few minutes ago informed me that he was trying to > eschew temporary storage of any kind, so I'm trying to think outside that > particular box. Well, I was trying to eschew *explicit* temporary storage. Temporary storage *must* exist, even if it's unnamed temporary storage that the compiler generates for intermediate results. As a puzzle, it was intended to remove *explicit* temporary storage. In that case some of the solutions (using @_, @ARGV, or %ENV) don't pass, but as a puzzle, it was (see my tag line) meant to be a playful way to learn. It's the what-if's that are interesting to me, and it was interesting to see how others bent and reinterpreted the rules. If you had fun or your learned, you won!!!! I learned a lot from working it myself. As an aside, when I was initially presented with the puzzle, I *almost* asked the answer, but resisted. I wanted to push against it rather than just be given the answer. I'm glad I did. Then out of (seemingly) nowhere, the solution just occurred to me. Really weird. I hadn't heard this trick before, but I knew enough of bit manipulations from my assembler days that I remembered the toggling trick of XOR. After not finding xor to be useful (but still taking up grey matter) for 20ish years, it occurred to me, and I scribbled down this simple binary math XOR rambling to prove that all permutations of 0 and 1 worked. 0011 a 0101 b ---- 0110 a^b -> a 0101 b ---- 0011 a^b -> b 0110 a ---- 0101 b^a -> a Two things impressed me: - Not focusing on it had the answer appear. The value of peripheral thinking, or my subconscious. - The similarity to superposition of waves -- it feels to me like two values looking at each other through a glass wall, then passing through it to the other side, superposing in the middle then coming through it unchanged to the other side. Wow! Whew! COoooolllll. My final obfuscated solution is this: $a ^= $b ^= $a ^= $b; And if I were playing golf: $a^=$b^=$a^=$b; (But I would *NOT* code it this way, not even with great comments.) But the destination doesn't show the journey. Here's the journey: # Original solution: # $a = $a ^ $b; # $b = $b ^ $a; # $a = $a ^ $b; # Refined to use op= # $a ^= $b; # $b ^= $a; # $a ^= $b; # Utilizing op= value, factored onto one line # $a ^= ($b ^= ($a ^= $b)); # Refined to remove unnecessary parens $a ^= $b ^= $a ^= $b; -- Michael R. Wolf All mammals learn by playing! MichaelRWolf@att.net From david.dyck at fluke.com Thu Oct 9 21:34:22 2003 From: david.dyck at fluke.com (David Dyck) Date: Mon Aug 2 21:37:10 2004 Subject: SPOILER Re: SPUG: scalar swap challenge In-Reply-To: <20031009104333.E18947@hobart.helvella.org> References: <22276559.1065646795054.JavaMail.root@thecount.psp.pas.earthlink.net> <20031009104333.E18947@hobart.helvella.org> Message-ID: On Thu, 9 Oct 2003 at 10:43 -0700, Colin Meyer wrote: > $a .= $b; > $b = substr $a, 0, length($a) - length($b); > $a = substr $a, length($b), length($a); Good, but how about using the replacement argument to substr. #!/usr/bin/perl $a = 'one'; $b = 'two'; print "$a $b\n"; $b = substr($a, 0, length $a, $b); print "$a $b\n"; __END__ substr EXPR,OFFSET,LENGTH,REPLACEMENT Extracts a substring out of EXPR and returns it. ... specify the replacement string as the 4th argument. This allows you to replace parts of the EXPR and return what was there before in one operation, just as you can with splice(). From cmeyer at helvella.org Fri Oct 10 02:34:09 2003 From: cmeyer at helvella.org (Colin Meyer) Date: Mon Aug 2 21:37:10 2004 Subject: SPOILER Re: SPUG: scalar swap challenge In-Reply-To: ; from david.dyck@fluke.com on Thu, Oct 09, 2003 at 07:34:22PM -0700 References: <22276559.1065646795054.JavaMail.root@thecount.psp.pas.earthlink.net> <20031009104333.E18947@hobart.helvella.org> Message-ID: <20031010003408.A20554@hobart.helvella.org> On Thu, Oct 09, 2003 at 07:34:22PM -0700, David Dyck wrote: > On Thu, 9 Oct 2003 at 10:43 -0700, Colin Meyer wrote: > > > $a .= $b; > > $b = substr $a, 0, length($a) - length($b); > > $a = substr $a, length($b), length($a); > > Good, but how about using the replacement argument to substr. > > #!/usr/bin/perl > $a = 'one'; > $b = 'two'; > > print "$a $b\n"; > $b = substr($a, 0, length $a, $b); > print "$a $b\n"; > Very nice. -Colin. From tim at consultix-inc.com Sun Oct 12 12:45:50 2003 From: tim at consultix-inc.com (Tim Maher) Date: Mon Aug 2 21:37:10 2004 Subject: SPUG: OpenSauceLunch: Thai in Ballard, 10/16 Message-ID: <20031012104550.A7720@timji.consultix-inc.com> I've just modified the SPUG-wiki page (see below for URL) to announce an Open Sauce Lunch for Thursday, 10/16, at the Thai Siam restaurant in Ballard at 12:30. I'll be showing my gratitude to those who recently reviewed chapters of my upcoming book by paying for their lunches, but all are welcome. Hope to see lots of you there! Remember to RSVP at the wiki if you're planning to come. -Tim ============================================================== | Tim Maher, Ph.D. tim(AT)teachmeperl.com | | SPUG Founder & Leader spug(AT)seattleperl.com | | Seattle Perl Users Group http://www.seattleperl.com | | SPUG Wiki Site http://spugwiki.perlocity.org | | Perl Certification Site http://perlcert.perlocity.org | ============================================================== From tim at consultix-inc.com Sun Oct 12 16:21:44 2003 From: tim at consultix-inc.com (Tim Maher) Date: Mon Aug 2 21:37:10 2004 Subject: SPUG: Order of -00 and -wln matters! Message-ID: <20031012142144.A8198@timji.consultix-inc.com> Anybody ever noticed that the relative order of -00 (for paragraph mode) and -wln is important? For example, see the program below. I haven't found any documentation of this behavior, which makes it seem more like a bug that a feature, although I think its deliberate. (Tested with 5.8.0). It seems that the $/ variable (and $\) gets set at the time -l is encountered in the left-to-right scan of the invocation options, rather than after all options have been processed (and -00 has a chance to change $/). $ perl -00 -wln -e 'print' code/memo This is the file "memo", which starts with these three lines spread out like so. And then it continues to a second paragraph. $ perl -wln -00 -e 'print' code/memo This is the file "memo", which starts with these three lines spread out like so. And then it continues to a second paragraph. $ -Tim *------------------------------------------------------------* | Tim Maher (206) 781-UNIX (866) DOC-PERL (866) DOC-UNIX | | tim(AT)Consultix-Inc.Com TeachMeUnix.Com TeachMePerl.Com | *+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-* | UNIX Fundamentals Class: 11/10-13 Perl Class: 12/01-05 | | Watch for my Book: "Minimal Perl for Shell Programmers" | *------------------------------------------------------------* From m3047 at inwa.net Sun Oct 12 16:40:18 2003 From: m3047 at inwa.net (Fred Morris) Date: Mon Aug 2 21:37:10 2004 Subject: SPUG: Part II: Coupling of closure parsing and compilation Message-ID: Here's a sample program and also some actual stats using anonymous closures as completion handlers. You'll notice that the anonymous version takes slightly more than twice as long as the "straight" call scenario. Don't read too much into that, it's not that surprising given not only the work of creating the closures, but also storing them in the hash that carries the object and then later retrieving them. The more salient point is that it's still managing on the order of 10000 closures per second (500 MHz K6, Perl 5.8.0 built for i586 Linux). The memory issue is the other one. "Straight" mode doesn't leak, of course. But you can clearly see that one technique for invoking handlers leaks and the other doesn't: the for loop leaks because it doesn't remove the references from the list of handlers, however the while/shift loop doesn't leak because it removes the references as a side effect. A little long for a sample, but kinda slick. Thanks to Yitzchak Scott-Thoennes for the early encouragement, and now I'll have to bend this technique to its real purpose. -- Fred Morris m3047@inwa.net -- #!/usr/bin/perl -w # =pod =head1 Test2 - Memory Leak Tester Demonstrates how anonymous callback handlers work. =cut package A; sub new( $$ ) { my $class = shift; my $write = shift; $write = 0 unless ($write); my $self = { write => $write }; return bless $self, $class; } # &new sub do_stuff( $$ ) { my $self = shift; my $param = shift; print "This is A, doing stuff.\n" if ($self->{write}); $self->{_b}->here_ya_go( sub { $self->finis( $param ); } ); } # &do_stuff sub also_do_stuff( $$ ) { my $self = shift; my $param = shift; print "This is A, doing stuff.\n" if ($self->{write}); } # &also_do_stuff sub finis( $$ ) { my $self = shift; my $param = shift; print "This is A ($param), saying until next time have a good tomorrow.\n" if ($self->{write}); } # &finis package B; sub new( $ ) { my $class = shift; my $write = shift; $write = 0 unless ($write); my $self = { write => $write }; return bless $self, $class; } # &new # Conceptually adds a to b. Actually, a has a pointer to b, not the other # way around. sub add( $$ ) { my $self = shift; my $a = shift; $a->{_b} = $self; } # &add sub here_ya_go( $$ ) { my $self = shift; my $handler = shift; push @{$self->{_handler}}, $handler; } # &here_ya_go sub do_more_stuff( $$ ) { my $self = shift; my $leak = shift; print "This is B, doing stuff.\n" if ($self->{write}); # If I'm right about this, leaving stuff in the handler stack # leads to a circular memory reference... or looking at it the # other way around, creating a shift register for handlers # prevents it! if ($leak) { foreach my $handler (@{$self->{_handler}}) { &$handler(); } } else { while (my $handler = shift @{$self->{_handler}}) { &$handler(); } } } # &do_more_stuff sub also_do_more_stuff( $$ ) { my $self = shift; my $leak = shift; print "This is B, doing stuff.\n" if ($self->{write}); } # &also_do_more_stuff package main; my $iterations = 1; my $a_calls = 2; my $leak = 0; my $write = 1; print "test> "; while (<>) { chomp; if (m/\?|help/io) { foreach my $cmd ('help','show','set [iterations|a_call|leak|write] n', 'exec [anonymous|straight]' ) { print " $cmd\n"; } print "\n"; } elsif (m/show/io) { print " iterations: $iterations\n"; print " a_calls: $a_calls\n"; print " leak: $leak\n"; print " write: $write\n"; print "\n"; } elsif (m/set\s+(\S+)\s+(\d+)/io) { my $n = $2; my $p = $1; if ($p =~ m/iter/io) { $iterations = $n; } elsif ($p =~ m/a_/io) { $a_calls = $n; } elsif ($p =~ m/leak/io) { $leak = $n; } elsif ($p =~ m/wri/io) { $write = $n; } } elsif (m/exec\s+(\S+)/io) { my $mode = $1; if ($mode =~ m/anon/io) { # Anonymous execution with handlers as closures. for( my $i = 0; $i < $iterations; $i++ ) { my $a = A->new( $write ); my $b = B->new( $write ); $b->add( $a ); for( my $j = 0; $j < $a_calls; $j++ ) { $a->do_stuff( $j ); } $b->do_more_stuff( $leak ); } } elsif ($mode =~ m/stra/io) { # Straight execution, without closures. for( my $i = 0; $i < $iterations; $i++ ) { my $a = A->new( $write ); my $b = B->new( $write ); $b->add( $a ); for( my $j = 0; $j < $a_calls; $j++ ) { $a->also_do_stuff( $j ); } # Leak doesn't really do anything since there are # no closures. $b->also_do_more_stuff( $leak ); for( my $j = 0; $j < $a_calls; $j++ ) { $a->finis( $j ); } } } } print "\ntest> "; } exit(0); __END__ m3047@flame:~> #initial m3047@flame:~> ps v | grep test2 | grep -v grep 11640 pts/1 S 0:00 323 1048 4503 1424 0.7 /usr/bin/perl -w ./test2.plx m3047@flame:~> #anon m3047@flame:~> ps v | grep test2 | grep -v grep 11640 pts/1 S 0:00 348 1048 4503 1524 0.7 /usr/bin/perl -w ./test2.plx m3047@flame:~> #straight m3047@flame:~> ps v | grep test2 | grep -v grep 11640 pts/1 S 0:00 348 1048 4503 1524 0.7 /usr/bin/perl -w ./test2.plx m3047@flame:~> #write = 0 m3047@flame:~> #iterations = 100000 m3047@flame:~> #anon m3047@flame:~> ps v | grep test2 | grep -v grep 11640 pts/1 S 0:40 349 1048 4503 1528 0.7 /usr/bin/perl -w ./test2.plx m3047@flame:~> #straight m3047@flame:~> ps v | grep test2 | grep -v grep 11640 pts/1 S 0:58 349 1048 4503 1528 0.7 /usr/bin/perl -w ./test2.plx m3047@flame:~> #anon m3047@flame:~> ps v | grep test2 | grep -v grep 11640 pts/1 S 1:39 349 1048 4503 1528 0.7 /usr/bin/perl -w ./test2.plx m3047@flame:~> #straight m3047@flame:~> ps v | grep test2 | grep -v grep 11640 pts/1 S 1:57 349 1048 4503 1528 0.7 /usr/bin/perl -w ./test2.plx m3047@flame:~> #iterations = 500 m3047@flame:~> #leak = 1 m3047@flame:~> #anon m3047@flame:~> ps v | grep test2 | grep -v grep 11640 pts/1 S 1:57 349 1048 5215 2240 1.1 /usr/bin/perl -w ./test2.plx m3047@flame:~> #straight m3047@flame:~> ps v | grep test2 | grep -v grep 11640 pts/1 S 1:57 349 1048 5215 2240 1.1 /usr/bin/perl -w ./test2.plx m3047@flame:~> #straight m3047@flame:~> ps v | grep test2 | grep -v grep 11640 pts/1 S 1:57 349 1048 5215 2240 1.1 /usr/bin/perl -w ./test2.plx m3047@flame:~> #anon m3047@flame:~> ps v | grep test2 | grep -v grep 11640 pts/1 S 1:57 349 1048 5931 2956 1.5 /usr/bin/perl -w ./test2.plx m3047@flame:~> From david.dyck at fluke.com Sun Oct 12 17:35:50 2003 From: david.dyck at fluke.com (David Dyck) Date: Mon Aug 2 21:37:10 2004 Subject: SPUG: Order of -00 and -wln matters! In-Reply-To: <20031012142144.A8198@timji.consultix-inc.com> References: <20031012142144.A8198@timji.consultix-inc.com> Message-ID: On Sun, 12 Oct 2003 at 14:21 -0700, Tim Maher wrote: > Anybody ever noticed that the relative order of -00 (for paragraph > mode) and -wln is important? There is a warning about this in the perlrun documentation, but I miss things all the time, and if you blink you'd skip over the note too. Note that the assignment "$\ = $/" is done when the switch is processed, so the input record separator can be different than the output record separator if the -l switch is followed by a -0 switch: From tim at consultix-inc.com Wed Oct 15 00:10:18 2003 From: tim at consultix-inc.com (Tim Maher) Date: Mon Aug 2 21:37:10 2004 Subject: SPUG: Need speaker for 21st! Message-ID: <20031014221018.A14321@timji.consultix-inc.com> Our scheduled speaker for next week's 10/21 meeting just canceled, due to a death in the family. Anybody want to jump in and take up the slack? Or does anybody have an idea for an alternative format, such as a total Q & A session, or Weakest Link competition, or anything else remotely Perlish? Warning: If nobody else comes forward, I might end up reading my TPJ article on Perl Certification (which just came out today on www.tpj.com) to the group -- so start brainstorming! 8-} -Tim *------------------------------------------------------------* | Tim Maher (206) 781-UNIX (866) DOC-PERL (866) DOC-UNIX | | tim(AT)Consultix-Inc.Com TeachMeUnix.Com TeachMePerl.Com | *+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-* | UNIX Fundamentals Class: 11/10-13 Perl Class: 12/01-05 | | Watch for my Book: "Minimal Perl for Shell Programmers" | *------------------------------------------------------------* From MichaelRWolf at att.net Wed Oct 15 12:05:12 2003 From: MichaelRWolf at att.net (Michael R. Wolf) Date: Mon Aug 2 21:37:10 2004 Subject: SPUG: Icons in Wiki don't all work Message-ID: I addded and updated a few organizational links under "Other Geekly Stuff" on the SPUG Wiki. http://spugwiki.perlocity.org/ Two of the three would allow me to add a link to their icons, but the third would not. Ideas how I could make the WSA icon work as an icon instead of as a link? An answer to the list or correct code at the Wiki would work. Thanks, Michael -- Michael R. Wolf All mammals learn by playing! MichaelRWolf@att.net From spug-list at l.ifokr.org Wed Oct 15 12:09:54 2003 From: spug-list at l.ifokr.org (Brian Hatch) Date: Mon Aug 2 21:37:10 2004 Subject: SPUG: Icons in Wiki don't all work In-Reply-To: References: Message-ID: <20031015170954.GV15513@ifokr.org> > > I addded and updated a few organizational links under "Other Geekly > Stuff" on the SPUG Wiki. http://spugwiki.perlocity.org/ > > Two of the three would allow me to add a link to their icons, but the > third would not. Ideas how I could make the WSA icon work as an icon > instead of as a link? > > An answer to the list or correct code at the Wiki would work. Could be they have images blocked when the referer isn't one of their websites. -- Brian Hatch Does the name Systems and Pavlov ring Security Engineer a bell? http://www.ifokr.org/bri/ Every message PGP signed -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://mail.pm.org/pipermail/spug-list/attachments/20031015/19e02fe9/attachment.bin From jmail at poplarware.com Wed Oct 15 12:36:17 2003 From: jmail at poplarware.com (Jennifer Hodgdon) Date: Mon Aug 2 21:37:10 2004 Subject: SPUG: Icons in Wiki don't all work In-Reply-To: Message-ID: <5.2.1.1.2.20031015103534.01bbd610@mail.poplarware.com> At 10:05 AM 10/15/2003, Michael R. Wolf wrote: >I addded and updated a few organizational links under "Other Geekly >Stuff" on the SPUG Wiki. http://spugwiki.perlocity.org/ > >Two of the three would allow me to add a link to their icons, but the >third would not. Ideas how I could make the WSA icon work as an icon >instead of as a link? It was the wrong path to the WSA logo - fixed on Wiki now. --Jennifer ____________________________ Jennifer Hodgdon Poplar ProductivityWare Practical Solutions for Office Tedium Reduction jmail@poplarware.com http://www.poplarware.com From tim at consultix-inc.com Thu Oct 16 10:37:51 2003 From: tim at consultix-inc.com (Tim Maher) Date: Mon Aug 2 21:37:10 2004 Subject: SPUG: Thai Lunch, Ballard, 12:30 Message-ID: <20031016083751.A18915@timji.consultix-inc.com> Just a reminder about today's Open Sauce Lunch at the Thai Siam restaurant (15th Ave. NW & NW 83rd St.) in Ballard at 12:30. I'll be showing my gratitude to those who recently reviewed chapters of my upcoming book by paying for their lunches, but all are welcome. Hope to see lots of you there! Remember to RSVP at the spugwiki if you're planning to come. -Tim ============================================================== | Tim Maher, Ph.D. tim(AT)teachmeperl.com | | SPUG Founder & Leader spug(AT)seattleperl.com | | Seattle Perl Users Group http://www.seattleperl.com | | SPUG Wiki Site http://spugwiki.perlocity.org | | Perl Certification Site http://perlcert.perlocity.org | ============================================================== From pdarley at kinesis-cem.com Thu Oct 16 10:58:44 2003 From: pdarley at kinesis-cem.com (Peter Darley) Date: Mon Aug 2 21:37:10 2004 Subject: SPUG: Off Topic Message-ID: Folks, Please excuse the off topic post, and if it's in-appropriate, please let me know and I shan't transgress again. :) I'm hoping there's someone out there who has a couple of minutes to answer a question I have about SCSI systems on Linux. If you can help, please contact me off list. I wouldn't bring it up here, but I'm getting kinda desperate. :) Thanks, Peter Darley From james at banshee.com Thu Oct 16 11:29:50 2003 From: james at banshee.com (James Moore) Date: Mon Aug 2 21:37:10 2004 Subject: SPUG: Off Topic In-Reply-To: Message-ID: <000701c39402$b8cffdf0$797ba8c0@gealach> I'm no expert (my stereo system is a SCSI setup, but not my servers), but I can give it a shot. I'll bet you a nickel that you've got termination problems. At least, that's always my problem. --------------------------- James Moore Skyline Properties, Inc. james@focusedrealestate.com Looking for a tech-friendly real estate agent? Mail me! > -----Original Message----- > From: spug-list-bounces@mail.pm.org [mailto:spug-list-bounces@mail.pm.org] > On Behalf Of Peter Darley > Sent: Thursday, October 16, 2003 8:59 AM > To: SPUG > Subject: SPUG: Off Topic > > Folks, > > Please excuse the off topic post, and if it's in-appropriate, please > let me > know and I shan't transgress again. :) > > I'm hoping there's someone out there who has a couple of minutes to > answer > a question I have about SCSI systems on Linux. If you can help, please > contact me off list. I wouldn't bring it up here, but I'm getting kinda > desperate. :) > > Thanks, > Peter Darley > > _____________________________________________________________ > Seattle Perl Users Group Mailing List > POST TO: spug-list@mail.pm.org http://spugwiki.perlocity.org > ACCOUNT CONFIG: http://mail.pm.org/mailman/listinfo/spug-list > MEETINGS: 3rd Tuesdays, U-District, Seattle WA > WEB PAGE: http://www.seattleperl.org From tim at consultix-inc.com Thu Oct 16 16:27:26 2003 From: tim at consultix-inc.com (Tim Maher) Date: Mon Aug 2 21:37:10 2004 Subject: SPUG: Call for "Lightning Talkers" Message-ID: <20031016142726.A19845@timji.consultix-inc.com> SPUGsters, Since nobody has stepped forward to fill in for our canceled speaker, it seems best to open up the meeting for "Lightning Talkers". So please think about what you could tell the rest of us in an informal talk of at least 3 minutes, and post your name and topic to the SPUGwiki page that's linked to the top bullet item there: http://spugwiki.perlocity.org/index.cgi?LightningTalks Ideas? You could tell us about that cool module you just started using, or a book you just read, or your insights into the Seattle job market, or what you like about Perl 6, or what you thought about Tim's article on Perl Certification in the latest Perl Journal (www.tpj.com), or anything else having something to do with Perl. SPUG is a cooperative enterprise, and works best when people help out by making a contribution! And you certainly don't have to develop a slick presentation, but if you want some visual aids, you could put some notes on the SPUGwiki and project them from there during the talk while using the hall's computer. I'm looking forward to seeing what we can come up with! -Tim *------------------------------------------------------------* | Tim Maher (206) 781-UNIX (866) DOC-PERL (866) DOC-UNIX | | tim(AT)Consultix-Inc.Com TeachMeUnix.Com TeachMePerl.Com | *+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-* | UNIX Fundamentals Class: 11/10-13 Perl Class: 12/01-05 | | Watch for my Book: "Minimal Perl for Shell Programmers" | *------------------------------------------------------------* From m3047 at inwa.net Thu Oct 16 17:47:14 2003 From: m3047 at inwa.net (Fred Morris) Date: Mon Aug 2 21:37:10 2004 Subject: SPUG: some notes from some Perl class Message-ID: Don't know who the instructor was, and I pass this link on without prejudice: http://www.911media.org/workshops/perlclass/ -- Fred Morris m3047@inwa.net From MichaelRWolf at att.net Mon Oct 20 10:13:20 2003 From: MichaelRWolf at att.net (Michael R. Wolf) Date: Mon Aug 2 21:37:10 2004 Subject: SPUG: Sys Admin position available - MS, LAMP (Red Hat, Apache, MySQL, Perl, PHP), networking In-Reply-To: <3F909627.2010909@resourcemaximizer.com> (Sherri Edwards's message of "Fri, 17 Oct 2003 18:23:51 -0700") References: <3F909627.2010909@resourcemaximizer.com> Message-ID: SPUG members, SAGE members, I received this through a friend of a friend. It looked looked interesting for someone with different skills from me -- possibly you! Enjoy, Michael Wolf > From: "Rakhel Wainey" > To: > Date: Fri, 17 Oct 2003 14:36:49 -0700 > Subject: [DE-Sea] Job Offered: IT Position > > Hello, all- > > I'm currently recruiting for the following position. It's a permanent > opportunity with an outstanding company located in Kirkland. Great > opportunity, great team! Forwards welcome, please contact me directly for > more information. > > Thanks! > Rakhel > > Rakhel Wainey | Director, Recruiting > Compella | A Professional Search & Consulting Firm > Tel: 206.353.1107 | Fax: 425.688.0014 > > > Requirements (2+ years with each of the following) > ========== > 1. MS Windows Network Administration > 2. Linux (Red Hat) Administration > 3. Routers Configuration > 4. Network Security > 5. Perl and PHP programming > 6. Web site administrat > ion (Apache server) and programming (PHP on a MySQL > database) > > Additional Qualifications > ================== > -Knowledge of build systems and make-files a plus > -Programming in C++ a plus > -Computer Science degree a plus. > > Duties > ===== > 1. Backups > 2. Network and router configuration > 3. Network and computer security > 4. Manage and configure exchange e-mail server > 5. Manage and program corporate and support web sites > 6. Purchase and configure computers and IT equipment > 7. Computer help desk > 8. Documenting the system and procedures -- Michael R. Wolf All mammals learn by playing! MichaelRWolf@att.net From tim at consultix-inc.com Mon Oct 20 11:26:09 2003 From: tim at consultix-inc.com (Tim Maher) Date: Mon Aug 2 21:37:10 2004 Subject: SPUG: 10/21 Meeting Details Message-ID: <20031020092609.A30778@timji.consultix-inc.com> October Seattle Perl Users Group Meeting -------------------------------------------------------- Title: "Lightning Talks" Speakers: The SPUG Brain Trust Meeting Time: Tuesday, Oct. 21, 2003 7-9pm Location: SAFECO bldg, Brooklyn St. and NE 45th St. Cost: Admission is free and open to the general public. Info: http://seattleperl.org/ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * This month, we'll have a selection of short talks from SPUGsters. If anybody else wants to squeeze in a short talk, let me know. See details below regarding RSVPs for the pre-meeting dinner. Here's what we've got so far: JonathanGardner DateTime, the solution to your date and time problems. FredMorris Perl-based firewall monitoring/control gizmo. I did 5 minutes on this at GSLUG a while back. It's here if you want it: http://devil.m3047.inwa.net/pub/fw-control/ 5 or 10 minutes to say "everything I know about Perl::Tk". AsimJalis MDef (http://mdef.sourceforge.net). A system for generating repetitive code using self-modifying macros. I will walk through mdef, and show you some applications. MDef can be used to generate database wrappers, object-oriented classes, HTML, and much more good stuff. TimMaher Will fill up time left vacant by other speakers, by presenting educational excerpts from his vast collection of Perl training classes Pre- and Post- Meeting Activities --------------------------------- The pre-meeting dinner will be at the Cedars restaurant, at 50th St. and Brooklyn, in the University District, near the Safeco building where the meeting will take place. The phone number is 527-5247. If you are planning to be there, please enter your name on the Kwiki RSVP page by 2pm on the meeting day. (NOTE: Arrival by 5:45pm is recommended for those ordering food). Those who comply with the RSVP policy, and are therefore counted in the seating reservation, will have top priority for seating at the speaker's table. -Tim *------------------------------------------------------------* | Tim Maher (206) 781-UNIX (866) DOC-PERL (866) DOC-UNIX | | tim(AT)Consultix-Inc.Com TeachMeUnix.Com TeachMePerl.Com | *+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-* | UNIX Fundamentals Class: 11/10-13 Perl Class: 12/01-05 | | Watch for my Book: "Minimal Perl for Shell Programmers" | *------------------------------------------------------------* From tim at consultix-inc.com Mon Oct 20 15:01:42 2003 From: tim at consultix-inc.com (Tim Maher) Date: Mon Aug 2 21:37:10 2004 Subject: SPUG: Perl contract, Bellevue Message-ID: <20031020130142.A31527@timji.consultix-inc.com> Perl Developer Required skills Essential Functions: * Produce Quality code on schedule, system analysis and design. Work with a variety of tools. Solve problems of low to moderate complexity at the project level. Work in a fast paced team environment. Secondary Functions: * Performing build and deployment activities on a moderate to high complexity. Required Skills * Must have a minimum of 4+ years of professional development experience. Strong experience in Perl, Java, J2EE, Oracle required. WebLogic and JSP experience desired. * BS Degree in Computer/Information Science or equivalent work experience required * Must be proficient with OOA & OOD. * Strong development background on UNIX/Linux/Solaris environment is highly desirable. * contract position avg. 2-3 months, pay range is hourly $35 * placement through recruiter * W-2 * physical location is downtown Seattle * company's product or service * Our client is an e-commerce company in the automotive industry Thank you!!!! Aimee Cook Technical Recruiter ConsultNet Empowering the World's largest network of computer professionals. ph: 206.234.4473 email: acook@consultnet-nw.com www.consult-net.com From alan at ufies.org Tue Oct 21 18:35:17 2003 From: alan at ufies.org (Alan) Date: Mon Aug 2 21:37:10 2004 Subject: SPUG: html->pdf conversion? Message-ID: <20031021233517.GL1799@ufies.org> Hey folks. I'm working on a project that will attempt to convert HTML to PDF. I found I can do this with html2ps and ps2pdf, and it works fine until you want fonts that aren't the standard serif and sans-serif. Being that my contract is with designer-type folks, this is important. The html2ps program will let you convert fonts other than the default ones, but they have to be in pfa format. After a bit of searching I found ttf2pfa, which works, but the results are, in a word, "sucky" :) They appear to be very low res and very block. The project doesn't look like much has happened with it since 1997 or so anyway. My clients aren't looking for anything extraordinary in the font front, just the standard windows fonts even (verdana, serif, helvetica, etc). Does anyone know of a different way to do this? Either a better way to do the conversion from html->pdf (saving the page size (a7, letter, etc) information preferrably) or a better way to embed trutype fonts into a postscript file. I know it's a bit off topic, but the list has been a bit dead lately and I wanted to stir things up a bit :) -- Alan - http://arcterex.net -------------------------------------------------------------------- "There are only 3 real sports: bull-fighting, car racing and mountain climbing. All the others are mere games." -- Hemingway From cwilkes-spug at ladro.com Tue Oct 21 19:00:12 2003 From: cwilkes-spug at ladro.com (Chris Wilkes) Date: Mon Aug 2 21:37:10 2004 Subject: SPUG: html->pdf conversion? In-Reply-To: <20031021233517.GL1799@ufies.org> References: <20031021233517.GL1799@ufies.org> Message-ID: <20031022000012.GB74764@www.ladro.com> On Tue, Oct 21, 2003 at 04:35:17PM -0700, Alan wrote: > > Does anyone know of a different way to do this? Either a better way to > do the conversion from html->pdf (saving the page size (a7, letter, etc) > information preferrably) or a better way to embed trutype fonts into a > postscript file. You might want to look at the Apache FOP project http://xml.apache.org/fop/ You'll have to learn about XSL-FO http://xml.apache.org/fop/fo.html http://xml.apache.org/fop/examples.html I would imagine there's an HTML->PDF converter in there somewhere. Chris From m3047 at inwa.net Tue Oct 21 19:14:52 2003 From: m3047 at inwa.net (Fred Morris) Date: Mon Aug 2 21:37:10 2004 Subject: SPUG: html->pdf conversion? Message-ID: At 4:35 PM 10/21/03, Alan wrote: >Hey folks. I'm working on a project that will attempt to convert HTML >to PDF. > >I found I can do this with html2ps and ps2pdf, and it works fine until >you want fonts that aren't the standard serif and sans-serif. Is html2ps including the fonts? Turn this off, and see if you can include them in the ps->pdf phase instead. Ghostscript should give you more control.. although the pdf driver is, yeah, a little bit sucky. I thought html2ps had options for page size, etc.? Or maybe you have to create your own prologue. Never fiddled with that. >[...] >After a bit of searching I found >ttf2pfa, which works, but the results are, in a word, "sucky" :) They >appear to be very low res and very block. 1) Make sure you're using real, scalable fonts.. and including them as such. 2) Think carefully about the resolution that you are converting for, both html->ps and ps->pdf... likewise think carefully about the device you are converting for. 3) They're "designer-types" and they won't spring for a legit copy of Acrobat? Hrmm. Acrobat comes with *the* ps to pdf convertor, and it will do what you want provided you use real scalable fonts, etc. etc. (The gizmo is called Distiller, and it has loads of options.) Do it right and you will get really sharp output; do it wrong and the results are, well, sucky. For that matter, Aladdin sells the latest version of GhostScript... they don't give it away! (never have, nothing new in that arrangement) 4) As a pre-press consideration, you may really want to not include those fonts, and instead pass them along to the printing shop so they can be downloaded to the RIP. 5) There are other artful ways of creating PostScript font routines, but it's more than a quick e-mail on a Perl list. 6) Sharper output almost invariably means larger size. 7) PostScript is a programming language; it's similar to Forth. :-p Whoever said prepress was WYSIWYG really didn't know much about hardware... either that or their idea of a notebook comes with crayons as a pointing device. There are shops which make their livings getting output press-ready... -- Fred Morris fredm3047@inwa.net (I-ACK) From alan at ufies.org Wed Oct 22 00:20:57 2003 From: alan at ufies.org (Alan) Date: Mon Aug 2 21:37:10 2004 Subject: SPUG: html->pdf conversion? In-Reply-To: References: <20031021233517.GL1799@ufies.org> Message-ID: <20031022052057.GA10941@ufies.org> On Tue, Oct 21, 2003 at 05:00:12PM -0700, Joshua Keroes wrote: > If you have access to a Mac OSX box, here's a pretty easy alternative: > 1. Run a webbrowser like Safari. > 2. Go to the URL in question. > 3. Print... | Save as PDF... Not really reasonable for a server, I'd hate to see the webmonkey clicking save as pdf in a slashdotting :) Sorry, should have specified before, this is for an online project, where designs are submitted in HTML, stored, and then output combined with user input as a PDF suitable for printing, etc. alan -- Alan - http://arcterex.net -------------------------------------------------------------------- "There are only 3 real sports: bull-fighting, car racing and mountain climbing. All the others are mere games." -- Hemingway From daryn at marinated.org Wed Oct 22 00:41:46 2003 From: daryn at marinated.org (Daryn Nakhuda) Date: Mon Aug 2 21:37:10 2004 Subject: SPUG: html->pdf conversion? References: <20031021233517.GL1799@ufies.org> <20031022052057.GA10941@ufies.org> Message-ID: <000f01c3985f$2eefac00$6501a8c0@platypus> ahh.. but if you did have access to a osx box, you could automate joshua's suggestion using applescript. ----- Original Message ----- From: "Alan" To: Sent: Tuesday, October 21, 2003 10:20 PM Subject: Re: SPUG: html->pdf conversion? > On Tue, Oct 21, 2003 at 05:00:12PM -0700, Joshua Keroes wrote: > > If you have access to a Mac OSX box, here's a pretty easy alternative: > > 1. Run a webbrowser like Safari. > > 2. Go to the URL in question. > > 3. Print... | Save as PDF... > > Not really reasonable for a server, I'd hate to see the webmonkey > clicking save as pdf in a slashdotting :) > > Sorry, should have specified before, this is for an online project, > where designs are submitted in HTML, stored, and then output combined > with user input as a PDF suitable for printing, etc. > > alan > -- > Alan - http://arcterex.net > -------------------------------------------------------------------- > "There are only 3 real sports: bull-fighting, car racing and mountain > climbing. All the others are mere games." -- Hemingway > _____________________________________________________________ > Seattle Perl Users Group Mailing List > POST TO: spug-list@mail.pm.org http://spugwiki.perlocity.org > ACCOUNT CONFIG: http://mail.pm.org/mailman/listinfo/spug-list > MEETINGS: 3rd Tuesdays, U-District, Seattle WA > WEB PAGE: http://www.seattleperl.org > > From alan at ufies.org Wed Oct 22 00:58:04 2003 From: alan at ufies.org (Alan) Date: Mon Aug 2 21:37:10 2004 Subject: SPUG: html->pdf conversion? In-Reply-To: <000f01c3985f$2eefac00$6501a8c0@platypus> References: <20031022052057.GA10941@ufies.org> <000f01c3985f$2eefac00$6501a8c0@platypus> Message-ID: <20031022055804.GD10941@ufies.org> Is that a realistic option for a potentially busy internet server? I'm confident enough in os/x, but nowadays for complex systems people won't even let perl run outside the apache process.... what happens if you get 10 hits/second (or even 1 a second)? Would applescript + distiller be able to keep up? I don't think that's a viable option, but it is an interesting thought :) On Tue, Oct 21, 2003 at 10:41:46PM -0700, Daryn Nakhuda wrote: > ahh.. but if you did have access to a osx box, you could automate joshua's > suggestion using applescript. > > > ----- Original Message ----- > From: "Alan" > To: > Sent: Tuesday, October 21, 2003 10:20 PM > Subject: Re: SPUG: html->pdf conversion? > > > > On Tue, Oct 21, 2003 at 05:00:12PM -0700, Joshua Keroes wrote: > > > If you have access to a Mac OSX box, here's a pretty easy alternative: > > > 1. Run a webbrowser like Safari. > > > 2. Go to the URL in question. > > > 3. Print... | Save as PDF... > > > > Not really reasonable for a server, I'd hate to see the webmonkey > > clicking save as pdf in a slashdotting :) > > > > Sorry, should have specified before, this is for an online project, > > where designs are submitted in HTML, stored, and then output combined > > with user input as a PDF suitable for printing, etc. > > > > alan > > -- > > Alan - http://arcterex.net > > -------------------------------------------------------------------- > > "There are only 3 real sports: bull-fighting, car racing and mountain > > climbing. All the others are mere games." -- Hemingway > > _____________________________________________________________ > > Seattle Perl Users Group Mailing List > > POST TO: spug-list@mail.pm.org http://spugwiki.perlocity.org > > ACCOUNT CONFIG: http://mail.pm.org/mailman/listinfo/spug-list > > MEETINGS: 3rd Tuesdays, U-District, Seattle WA > > WEB PAGE: http://www.seattleperl.org > > > > > > _____________________________________________________________ > Seattle Perl Users Group Mailing List > POST TO: spug-list@mail.pm.org http://spugwiki.perlocity.org > ACCOUNT CONFIG: http://mail.pm.org/mailman/listinfo/spug-list > MEETINGS: 3rd Tuesdays, U-District, Seattle WA > WEB PAGE: http://www.seattleperl.org -- Alan - http://arcterex.net -------------------------------------------------------------------- "There are only 3 real sports: bull-fighting, car racing and mountain climbing. All the others are mere games." -- Hemingway From alan at ufies.org Wed Oct 22 12:09:44 2003 From: alan at ufies.org (Alan) Date: Mon Aug 2 21:37:10 2004 Subject: SPUG: html->pdf conversion? In-Reply-To: <20031022084805.A5048@timji.consultix-inc.com> References: <20031021233517.GL1799@ufies.org> <20031022084805.A5048@timji.consultix-inc.com> Message-ID: <20031022170944.GD5014@ufies.org> > I have the same need for my book project, in which I'm writing > in a (modified) POD format, and then having to convert to MS-Word > and PDF for distribution to various parties. I too have found the > standard converters to be deficient, so I have compromised on > this routine that works best: > > * convert POD to Html using pod2html > * use Netscape Navigator to save HTML as PS > (works much better than the Linux html2ps command itself) > I looked to see if Navigator was running an external > command to do this conversion, but AFAIK it's doing it > internally > * run ps2pdf > > The PDF comes out looking great! I've considered this, but it has to run on an internet server and server any number of clients :( Someone already suggested having it run applescript to use acrobat to do the conversion :) However, if there's a way to run mozilla/netscape from the command line and do this, let me know! :) -- Alan - http://arcterex.net -------------------------------------------------------------------- "There are only 3 real sports: bull-fighting, car racing and mountain climbing. All the others are mere games." -- Hemingway From joneil at cobaltgroup.com Wed Oct 22 12:22:25 2003 From: joneil at cobaltgroup.com (O'neil, Jerome) Date: Mon Aug 2 21:37:10 2004 Subject: SPUG: html->pdf conversion? Message-ID: <25160AB2660F8B449892B0EB9C29C165C1F903@ex-sea-is2.cobaltgroup.com> Have you thought about using the OpenOffice API's to do this? Version 1.1 reads and writes PDF. -Jerome -----Original Message----- From: Alan [mailto:alan@ufies.org] Sent: Wednesday, October 22, 2003 10:10 AM To: spug-list@pm.org Subject: Re: SPUG: html->pdf conversion? > I have the same need for my book project, in which I'm writing > in a (modified) POD format, and then having to convert to MS-Word > and PDF for distribution to various parties. I too have found the > standard converters to be deficient, so I have compromised on > this routine that works best: > > * convert POD to Html using pod2html > * use Netscape Navigator to save HTML as PS > (works much better than the Linux html2ps command itself) > I looked to see if Navigator was running an external > command to do this conversion, but AFAIK it's doing it > internally > * run ps2pdf > > The PDF comes out looking great! I've considered this, but it has to run on an internet server and server any number of clients :( Someone already suggested having it run applescript to use acrobat to do the conversion :) However, if there's a way to run mozilla/netscape from the command line and do this, let me know! :) -- Alan - http://arcterex.net -------------------------------------------------------------------- "There are only 3 real sports: bull-fighting, car racing and mountain climbing. All the others are mere games." -- Hemingway _____________________________________________________________ Seattle Perl Users Group Mailing List POST TO: spug-list@mail.pm.org http://spugwiki.perlocity.org ACCOUNT CONFIG: http://mail.pm.org/mailman/listinfo/spug-list MEETINGS: 3rd Tuesdays, U-District, Seattle WA WEB PAGE: http://www.seattleperl.org This e-mail transmission contains information intended only for the use of the recipient(s) named above. Further, it contains information that may be privileged and confidential. If you are not the intended recipient, you are hereby notified that any dissemination, distribution, or copying of this message (including any attachments) is strictly prohibited. If you have received this e-mail in error, please notify the sender by reply e-mail and then delete this message from your mail system. Thank you for your compliance. From joneil at cobaltgroup.com Wed Oct 22 13:18:01 2003 From: joneil at cobaltgroup.com (O'neil, Jerome) Date: Mon Aug 2 21:37:10 2004 Subject: SPUG: html->pdf conversion? Message-ID: <25160AB2660F8B449892B0EB9C29C165C1F907@ex-sea-is2.cobaltgroup.com> On Wed, Oct 22, 2003 at 10:22:25AM -0700, O'neil, Jerome wrote: >> Have you thought about using the OpenOffice API's to do this? Version 1.1 >> reads and writes PDF. > >> -Jerome > *What API?* Tell me more! This one: http://download.services.openoffice.org/ooo/dev_docs/source/sdk/index.html I've just discovered it myself three days ago, so my experience is fairly limited, but my initial impressions are that it's fantastalicious. The documentation is verbose (900 page developer guide!), and rich with examples. I've yet to work through an example that didn't execute as advertised. The SDK API's are described through an IDL, so they are language independent. They provide bindings for Java, OOBasic, and C++. You get object representations of all the OO stuff, including draw, spreadsheet, and document. While there isn't a Perl language binding, I'm sure someone, somewhere could provide an XS implementation over the C++ stuff. I'm using it to put together a digital Foucault tester for telescope mirrors, and have found it quite nice. Who knew?! -Jerome This e-mail transmission contains information intended only for the use of the recipient(s) named above. Further, it contains information that may be privileged and confidential. If you are not the intended recipient, you are hereby notified that any dissemination, distribution, or copying of this message (including any attachments) is strictly prohibited. If you have received this e-mail in error, please notify the sender by reply e-mail and then delete this message from your mail system. Thank you for your compliance. From alan at ufies.org Wed Oct 22 13:23:53 2003 From: alan at ufies.org (Alan) Date: Mon Aug 2 21:37:10 2004 Subject: SPUG: html->pdf conversion? In-Reply-To: <20031022105550.A5470@timji.consultix-inc.com> References: <25160AB2660F8B449892B0EB9C29C165C1F903@ex-sea-is2.cobaltgroup.com> <20031022105550.A5470@timji.consultix-inc.com> Message-ID: <20031022182353.GF5014@ufies.org> On Wed, Oct 22, 2003 at 10:55:50AM -0700, Tim Maher/CONSULTIX wrote: > On Wed, Oct 22, 2003 at 10:22:25AM -0700, O'neil, Jerome wrote: > > Have you thought about using the OpenOffice API's to do this? Version 1.1 > > reads and writes PDF. > > > > -Jerome > > *What API?* Tell me more! Not sure if it'll work for your situation, but I found a bit of information at http://api.openoffice.org/docs/DevelopersGuide/FirstSteps/FirstSteps.htm#1+3+3+3+Make+the+office+listen via http://www.oooforum.org/forum/viewtopic.php?t=2977&highlight=command+line Might help me as well. Regarding the html->pdf situation, it looks like you can do ooffice -p foo.xyz and if the default printer is a postscript print to file, it'll output to the file. Haven't got enough set up yet. The api.oo.o might be good though. alan -- Alan - http://arcterex.net -------------------------------------------------------------------- "There are only 3 real sports: bull-fighting, car racing and mountain climbing. All the others are mere games." -- Hemingway From itayf at fhcrc.org Thu Oct 23 12:30:55 2003 From: itayf at fhcrc.org (Itay Furman) Date: Mon Aug 2 21:37:10 2004 Subject: SPUG: html->pdf conversion? In-Reply-To: <20031022170944.GD5014@ufies.org> Message-ID: On Wed, 22 Oct 2003, Alan wrote: > > I have the same need for my book project, in which I'm writing > > in a (modified) POD format, and then having to convert to MS-Word > > and PDF for distribution to various parties. I too have found the > > standard converters to be deficient, so I have compromised on > > this routine that works best: > > > > * convert POD to Html using pod2html > > * use Netscape Navigator to save HTML as PS > > (works much better than the Linux html2ps command itself) > > I looked to see if Navigator was running an external > > command to do this conversion, but AFAIK it's doing it > > internally > > * run ps2pdf > > > > The PDF comes out looking great! > An alternative could be * POD to LaTeX using pod2latex * LaTeX to PDF using pdflatex. I'm using latex/pdflatex for sometime, but didn't check the pod2latex converter (didn't have to, so far). Itay From pdarley at kinesis-cem.com Thu Oct 23 15:48:13 2003 From: pdarley at kinesis-cem.com (Peter Darley) Date: Mon Aug 2 21:37:11 2004 Subject: FW: SPUG: html->pdf conversion? Message-ID: Folks, It looks like due to an error with mail account setup this never went out, so I'm re-sending it. Thanks, Peter Darley -----Original Message----- From: Peter Darley [mailto:pdarley@darleyconsulting.com] Sent: Wednesday, October 22, 2003 7:05 AM To: Alan; spug-list@pm.org Subject: RE: SPUG: html->pdf conversion? Alan, The windows Acrobat software is able to run in a 'server' mode where it is assigned an input and output directory, and everything that is put into the input directory gets automatically converted to a .pdf and dumped into the output directory. I'm 90% sure that it can take HTML, as well as office and desktop publishing files. This would allow you to not have to do any squirly pre or post processing. I don't know if there's a Linux version of Acrobat, but I suspect there is, and I suspect that it will do the same thing. I used this method to automatically generate .pdf reports in a previous job from .xls documents. With Samba you could even just have the conversion part on the windows machine, and write and read from a share, if there's not a Linux version that does what you want. Thanks, Peter Darley -----Original Message----- From: spug-list-bounces@mail.pm.org [mailto:spug-list-bounces@mail.pm.org]On Behalf Of Alan Sent: Tuesday, October 21, 2003 10:21 PM To: spug-list@pm.org Subject: Re: SPUG: html->pdf conversion? On Tue, Oct 21, 2003 at 05:00:12PM -0700, Joshua Keroes wrote: > If you have access to a Mac OSX box, here's a pretty easy alternative: > 1. Run a webbrowser like Safari. > 2. Go to the URL in question. > 3. Print... | Save as PDF... Not really reasonable for a server, I'd hate to see the webmonkey clicking save as pdf in a slashdotting :) Sorry, should have specified before, this is for an online project, where designs are submitted in HTML, stored, and then output combined with user input as a PDF suitable for printing, etc. alan -- Alan - http://arcterex.net -------------------------------------------------------------------- "There are only 3 real sports: bull-fighting, car racing and mountain climbing. All the others are mere games." -- Hemingway _____________________________________________________________ Seattle Perl Users Group Mailing List POST TO: spug-list@mail.pm.org http://spugwiki.perlocity.org ACCOUNT CONFIG: http://mail.pm.org/mailman/listinfo/spug-list MEETINGS: 3rd Tuesdays, U-District, Seattle WA WEB PAGE: http://www.seattleperl.org From m3047 at inwa.net Thu Oct 23 16:36:50 2003 From: m3047 at inwa.net (Fred Morris) Date: Mon Aug 2 21:37:11 2004 Subject: SPUG: Open Sauce - King Cafe 11:45AM Message-ID: I thought I'd go have Dim Sum at the King Cafe tomorrow (Friday the 24th). I'll be there at 11:45AM, and the first $20 is on me... that should be enough for several people to eat well! The King Cafe is a little hole in the wall across the street more or less from House Of Hong in Seattle's International District, at 723 South King Street. Do *not* confuse this place with the King Street Cafe (which isn't even on King!). The place does a roaring takeout business, although it does have some seating upstairs (hence 11:45). If you're planning on attending shoot me back an e-mail, or call me at the number in the sig. I'll be white guy eating chicken feet. :-p Don't worry, they have other stuff (Dim Sum is all they do, and they're only open for lunch). -- Fred Morris m3047@inwa.net 206.329.8800 x118 samurai tech support! From m3047 at inwa.net Thu Oct 23 20:22:53 2003 From: m3047 at inwa.net (Fred Morris) Date: Mon Aug 2 21:37:11 2004 Subject: SPUG: Open Sauce - King Cafe 11:45AM Message-ID: Tim Maher wrote: >Why don't you invite people to RSVP on the Kwiki, as >they're already conditioned >to do? Well by golly, because I didn't! There's a kwiki page now: http://spugwiki.perlocity.org/index.cgi?FridayOct24InternationalDistrict -- Fred Morris m3047@at@inwa.net From samca at closehauled.com Fri Oct 24 02:26:40 2003 From: samca at closehauled.com (Sam Carpenter) Date: Mon Aug 2 21:37:11 2004 Subject: SPUG: Login Page and Cookies Message-ID: <6906BE0C-05F3-11D8-BF26-0003937B36CA@closehauled.com> I am just getting started with Perl (switching from Java and .NET) and I have a project where I want to create a login page instead of using .htaccess. I have the book, "Writing CGI Applications with Perl" by Kevin Meltzer and Brent Michalski. The authors have an example application (chapter 14) where they create a login page and use the CGI module to set and verify cookies to verify whether a user is logged in or not. Is this an acceptable way to manage user logins? For clarification, I am just writing a simple quoting application for a customer with less than 10 users. Therefore the security doesn't need to be bullet-proof but it should be somewhat trustworthy. I am not going with .htaccess for aesthetic reasons and a custom login page gives me easy access to the user id (assuming that getting through .htaccess would be difficult?). Thanks, Sam Carpenter Closehauled Solutions, LLC From ben at reser.org Fri Oct 24 03:42:02 2003 From: ben at reser.org (Ben Reser) Date: Mon Aug 2 21:37:11 2004 Subject: SPUG: Login Page and Cookies In-Reply-To: <6906BE0C-05F3-11D8-BF26-0003937B36CA@closehauled.com> References: <6906BE0C-05F3-11D8-BF26-0003937B36CA@closehauled.com> Message-ID: <20031024084202.GQ6803@titanium.brain.org> On Fri, Oct 24, 2003 at 12:26:40AM -0700, Sam Carpenter wrote: > I am just getting started with Perl (switching from Java and .NET) and > I have a project where I want to create a login page instead of using > .htaccess. I have the book, "Writing CGI Applications with Perl" by > Kevin Meltzer and Brent Michalski. The authors have an example > application (chapter 14) where they create a login page and use the CGI > module to set and verify cookies to verify whether a user is logged in > or not. Is this an acceptable way to manage user logins? Yes. I just recently implemented something like this. I set a cookie with the following information: userid time issued time cookie expires (this is in the data section, you can't rely on the browser expiring the cookie for security reasons) mask which specifies what permissions are given to the user md5 hash of the above data and a secret that is only held on the server. Once that cookie is set you can verify their access by looking for the cookie, taking the data and the secret and regenerating the hash. If the hash you generated and the hash in the cookie match you can trust the access the cookies says it has. You could also throw in an ip address mask of some sort on there to help limit replaying someone elses credentials. If you need further information just ask. It's late so I'm probably not making as much sense as I should nor am I providing code examples... > For clarification, I am just writing a simple quoting application for a > customer with less than 10 users. Therefore the security doesn't need > to be bullet-proof but it should be somewhat trustworthy. I am not > going with .htaccess for aesthetic reasons and a custom login page > gives me easy access to the user id (assuming that getting through > .htaccess would be difficult?). Actually it's easier. It's provided to you in the REMOTE_USER environment variable by the webserver. -- Ben Reser http://ben.reser.org "Conscience is the inner voice which warns us somebody may be looking." - H.L. Mencken From samca at closehauled.com Fri Oct 24 04:11:56 2003 From: samca at closehauled.com (Sam Carpenter) Date: Mon Aug 2 21:37:11 2004 Subject: SPUG: Login Page and Cookies In-Reply-To: <20031024084202.GQ6803@titanium.brain.org> Message-ID: <1D65762F-0602-11D8-BF26-0003937B36CA@closehauled.com> On Friday, October 24, 2003, at 01:42 AM, Ben Reser wrote: > If you need further information just ask. It's late so I'm probably > not > making as much sense as I should nor am I providing code examples... Ben, you make perfect sense - I really appreciate your help! I just need to figure out how to generate the md5 hash and I will be all set (something I am sure I can find on perldoc or CPAN). > Actually it's easier. It's provided to you in the REMOTE_USER > environment variable by the webserver. This might be a way to go as well. Thanks again for your help, -Sam From pdarley at kinesis-cem.com Fri Oct 24 10:36:14 2003 From: pdarley at kinesis-cem.com (Peter Darley) Date: Mon Aug 2 21:37:11 2004 Subject: SPUG: Login Page and Cookies In-Reply-To: <6906BE0C-05F3-11D8-BF26-0003937B36CA@closehauled.com> Message-ID: Sam, You might want to look at the Apache::Session stuff if you're using mod_perl. It'll handle the cookies for you, and it only takes a couple of lines to implement. Additionally it will allow you to have session variables (saving states between page hits), which can be very nice. It can use a variety of databases and files to store the session info. Check out http://theoryx5.uwinnipeg.ca/CPAN/data/Apache-Session/Session.html. If you want any sample code using this for access control let me know. Thanks, Peter Darley -----Original Message----- From: spug-list-bounces@mail.pm.org [mailto:spug-list-bounces@mail.pm.org]On Behalf Of Sam Carpenter Sent: Friday, October 24, 2003 12:27 AM To: spug-list@mail.pm.org Subject: SPUG: Login Page and Cookies I am just getting started with Perl (switching from Java and .NET) and I have a project where I want to create a login page instead of using .htaccess. I have the book, "Writing CGI Applications with Perl" by Kevin Meltzer and Brent Michalski. The authors have an example application (chapter 14) where they create a login page and use the CGI module to set and verify cookies to verify whether a user is logged in or not. Is this an acceptable way to manage user logins? For clarification, I am just writing a simple quoting application for a customer with less than 10 users. Therefore the security doesn't need to be bullet-proof but it should be somewhat trustworthy. I am not going with .htaccess for aesthetic reasons and a custom login page gives me easy access to the user id (assuming that getting through .htaccess would be difficult?). Thanks, Sam Carpenter Closehauled Solutions, LLC _____________________________________________________________ Seattle Perl Users Group Mailing List POST TO: spug-list@mail.pm.org http://spugwiki.perlocity.org ACCOUNT CONFIG: http://mail.pm.org/mailman/listinfo/spug-list MEETINGS: 3rd Tuesdays, U-District, Seattle WA WEB PAGE: http://www.seattleperl.org From aaron at activox.com Fri Oct 24 11:26:36 2003 From: aaron at activox.com (Aaron Salo) Date: Mon Aug 2 21:37:11 2004 Subject: SPUG: Login Page and Cookies In-Reply-To: <1D65762F-0602-11D8-BF26-0003937B36CA@closehauled.com> References: <20031024084202.GQ6803@titanium.brain.org> Message-ID: <3.0.5.32.20031024092636.0152af10@mail.activox.com> At 02:11 AM 10/24/2003 -0700, Sam Carpenter wrote: >Ben, you make perfect sense - I really appreciate your help! I just >need to figure out how to generate the md5 hash and I will be all set >(something I am sure I can find on perldoc or CPAN). If you're running on apache, and mod_unique_id is turned on, you should be able to take advantage of that. my $lstring = $ENV{'UNIQUE_ID'}; will give you a unique id you can use as a session tracker or etc. If not, scroll down to the end of this note for a quickie package to make a somewhat unique MD5 hashed string. While on topic, one thing about cookies is that some people wanna pop a half dozen separate ones to track six values. Using CGI.pm this is not necessary cause you can put multiple name/val pairs into a hash and just throw the hash into a single cookie. Here is a code snip that illustrates how to do that Note: cookies are inherently Not Secure. People can easily manip them. So with only a little extra work, you can make them pretty secure. After I auth a user, I stuff the UNIQUE_ID into the table along with their other info. Then on all subsequent page calls, I check the value in the cookie against the value in the db. This prevents someone from manually hacking the cuid in their cookie and trying to get access to a different user's account. If they change the cuid in their cookie, their hash string won't match the hash string for the uid they're trying to hijack, and they get booted out of the system on the next page call. Bam. The snip below presumes you have already auth'd the user and fetched their variables out of the appropriate db table and have those variables exposed (like $fname, $lname, etc...). ================ PUTTING STUFF IN using cookie leverage in CGI.pm ================ use CGI qw(:standard); my %AuthCookie; my $lstring = $ENV{'UNIQUE_ID'}; my $sth = $dbh->prepare($sql) or die "$DBI::errstr"; $sth->execute($ipaddr, $lstring, $cuid) or die "$DBI::errstr"; # cookie time - set it $AuthCookie{'cuid'} = $cuid; $AuthCookie{'lstring'} = $lstring; $AuthCookie{'fname'} = $fname; $AuthCookie{'lname'} = $lname; $AuthCookie{'email'} = $email; $AuthCookie{'ccid'} = $ccid; # make a hash cookie. mmmmm. cookie. my $cookie = cookie( -name=> 'AuthToken', -value=> \%AuthCookie, -path=> '/', ); # give them the cookie print header(-"cookie"=>$cookie); } ========================== GETTING STUFF OUT using cookie leverage in CGI.pm ========================== # once you've set the hash cookie above # you can get the vals using keys, just like manip of a normal hash # life is sooooooo damned good my %authcookie = cookie('AuthToken'); my $Xcuid = $authcookie{'cuid'}; my $Xlstring = $authcookie{'lstring'}; my $Xfname = $authcookie{'fname'}; my $Xlname = $authcookie{'lname'}; my $Xemail = $authcookie{'email'}; my $Xccid = $authcookie{'ccid'}; ============================== ROLLING YOUR OWN UNIQUE KEY if mod_unique_id is not available ============================== # here is a tiny module that throws the gimme_key function # using MD5 - save the next few hunks as Enc.pm ===snip====== package Enc; require Exporter; @ISA = qw(Exporter); @EXPORT = qw (gimme_key); use MD5; sub gimme_key { my @rec = @_; my $md5 = new MD5; my $phrase = join('', @rec, time); $md5->add($phrase); my $id = $md5->hexdigest(); return $id; } 1; ====snip========= # now use this in your program by calling use Enc; # voila. here's how you get a unique keystring # throw the function a value somewhat unique # like the user's email address, their uid # or whatever you have available # you'll be cool as long as two people don't throw the same value # in the same second which is pretty okay mostly. mostly. # NOTE - if you don't throw a value here, and you ask for two keys in the same second # they will be identical - that would probably be bad. my $key = gimme_key($userid, $useremail, $whatever_you_got, $budget_deficit, $can_opener, $foo, $bar, $you_get_the_drift); Hope this is useful Aaron From ben at reser.org Fri Oct 24 11:40:17 2003 From: ben at reser.org (Ben Reser) Date: Mon Aug 2 21:37:11 2004 Subject: SPUG: Login Page and Cookies In-Reply-To: <1D65762F-0602-11D8-BF26-0003937B36CA@closehauled.com> References: <20031024084202.GQ6803@titanium.brain.org> <1D65762F-0602-11D8-BF26-0003937B36CA@closehauled.com> Message-ID: <20031024164017.GR6803@titanium.brain.org> On Fri, Oct 24, 2003 at 02:11:56AM -0700, Sam Carpenter wrote: > On Friday, October 24, 2003, at 01:42 AM, Ben Reser wrote: > >If you need further information just ask. It's late so I'm probably > >not > >making as much sense as I should nor am I providing code examples... > > Ben, you make perfect sense - I really appreciate your help! I just > need to figure out how to generate the md5 hash and I will be all set > (something I am sure I can find on perldoc or CPAN). use Digest::MD5 qw(md5_base64); md5_base64($data); > >Actually it's easier. It's provided to you in the REMOTE_USER > >environment variable by the webserver. > > This might be a way to go as well. Yeah probably is. It's what I usually use. In this particular project I used the cookie thing on the user had to enter 3 values not just 2, so it wasn't possible to do that easily with simple authentication. -- Ben Reser http://ben.reser.org "Conscience is the inner voice which warns us somebody may be looking." - H.L. Mencken From bill at celestial.com Fri Oct 24 11:41:15 2003 From: bill at celestial.com (Bill Campbell) Date: Mon Aug 2 21:37:11 2004 Subject: SPUG: Login Page and Cookies In-Reply-To: <3.0.5.32.20031024092636.0152af10@mail.activox.com> References: <20031024084202.GQ6803@titanium.brain.org> <3.0.5.32.20031024092636.0152af10@mail.activox.com> Message-ID: <20031024164115.GA33009@alexis.mi.celestial.com> On Fri, Oct 24, 2003, Aaron Salo wrote: >At 02:11 AM 10/24/2003 -0700, Sam Carpenter wrote: >>Ben, you make perfect sense - I really appreciate your help! I just >>need to figure out how to generate the md5 hash and I will be all set >>(something I am sure I can find on perldoc or CPAN). I would suggest looking at the CGI::Application, CGI::Session, and HTML::Template modules from CPAN. These can save you considerable effort. Bill -- INTERNET: bill@Celestial.COM Bill Campbell; Celestial Software LLC UUCP: camco!bill PO Box 820; 6641 E. Mercer Way FAX: (206) 232-9186 Mercer Island, WA 98040-0820; (206) 236-1676 URL: http://www.celestial.com/ ``Now if there is one thing that we do worse than any other nation, it is try and manage somebody else's affairs.'' Will Rogers From tim at consultix-inc.com Sat Oct 25 12:43:01 2003 From: tim at consultix-inc.com (Tim Maher) Date: Mon Aug 2 21:37:11 2004 Subject: SPUG: Software to expand contractions? Message-ID: <20031025104301.A13670@timji.consultix-inc.com> Dudes, I'm getting complaints from some early reviewers of my book about all the "contractions" I'm using in my writing! So last night I set out to write a Perl script to make changes like the following: That's => That is He's => He is They're => They are We're => We are Then I realized that the 's ending usually needs replacement by "is", so I tried "'s" => ' is' which doesn't quite work, because of the undesirability of changing Larry's hat => Larry is hat After making an exception for that case, I found other complications, such as wouldn't => would not can't => can not These follow different rules, because the 'wouldn' loses its 'n', but the 'can' doesn't! So at that point I realized that this is a bigger problem than I first thought, and decided to look for a solution on CPAN. Searching for "contractions" didn't turn up anything relevant, so now I'm wondering if anybody knows of a module that will do this job -- convert a standard set of English contractions into their expanded forms. Can't y'all gimme the help I'm searchin' for? -Tim *------------------------------------------------------------* | Tim Maher (206) 781-UNIX (866) DOC-PERL (866) DOC-UNIX | | tim(AT)Consultix-Inc.Com TeachMeUnix.Com TeachMePerl.Com | *+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-* | UNIX Fundamentals Class: 11/10-13 Perl Class: 12/01-05 | | Watch for my Book: "Minimal Perl for Shell Programmers" | *------------------------------------------------------------* From stuart_poulin at yahoo.com Sun Oct 26 18:54:12 2003 From: stuart_poulin at yahoo.com (Stuart Poulin) Date: Mon Aug 2 21:37:11 2004 Subject: SPUG: Software to expand contractions? In-Reply-To: <20031025104301.A13670@timji.consultix-inc.com> Message-ID: <20031027005412.14309.qmail@web80605.mail.yahoo.com> 's is also a contraction for "has". i..e "It's been proven" "He's" could be "He is" or "He has" depending on context. I'd say keep the contractions in - less words to read. Tim Maher wrote: Dudes, I'm getting complaints from some early reviewers of my book about all the "contractions" I'm using in my writing! So last night I set out to write a Perl script to make changes like the following: That's => That is He's => He is They're => They are We're => We are Then I realized that the 's ending usually needs replacement by "is", so I tried "'s" => ' is' --------------------------------- Do you Yahoo!? Exclusive Video Premiere - Britney Spears -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.pm.org/pipermail/spug-list/attachments/20031026/3c0e21da/attachment.htm From legrady at earthlink.net Sun Oct 26 19:44:39 2003 From: legrady at earthlink.net (Tom Legrady) Date: Mon Aug 2 21:37:11 2004 Subject: SPUG: Software to expand contractions? In-Reply-To: <20031027005412.14309.qmail@web80605.mail.yahoo.com> References: <20031027005412.14309.qmail@web80605.mail.yahoo.com> Message-ID: <3F9C7887.2080302@earthlink.net> he's == he has ???? Can you provide an example? Re-write the excessive contractions, they interfere with fluid reading. Tom Stuart Poulin wrote: > 's is also a contraction for "has". > i..e "It's been proven" > > "He's" could be "He is" or "He has" depending on context. > > I'd say keep the contractions in - less words to read. From kahn at cpan.org Sun Oct 26 19:53:10 2003 From: kahn at cpan.org (Jeremy G Kahn) Date: Mon Aug 2 21:37:11 2004 Subject: SPUG: Software to expand contractions? In-Reply-To: <20031025104301.A13670@timji.consultix-inc.com> References: <20031025104301.A13670@timji.consultix-inc.com> Message-ID: <3F9C7A86.6060401@cpan.org> WARNING: non-language geeks, avert your eyes. Well, you could cope with "wouldn't" and "can't" by having an exception table with just "can't" and handling the rest by rule (where that rule is s/n't$/ not/g). You can handle "can't" and "won't" with special cases, handle otherwise "-n't", "-'d", "-'ll" and "-'ve" cases with general rules, but you're not going to be able to solve the general case for 's without some heuristics or some grammatical knowledge. For example: Larry's been going at it. ("Larry has ..." Larry's hat ("Larry's") The traditional grammarian explanation is that "'s" represents "has" when the following word is a past participle: Larry's beaten the system => "has" Larry's gone home => "has" Larry's had a bad day => "has" "beaten", "gone", "had => all past participles. This looks doable (with a dictionary): Here's the English rule, pseudo-emperlified and untested (also modulo concerns about capitalization) s/'s (\w+)/ is_past_part($1) ? " has $1":"'s $1"/eg; BUT. But what are the conditions in which "'s" represents "is"? Larry's skiing trip was needed. => "'s" Larry's skiing is good => "'s" Larry's hat is phat. => "'s" Larry's jealousy => "'s" Larry's coding up a storm. => "is" Larry's phat. => "is" Larry's jealous. => "is" There are two more cases where "is" is the correct expansion: * when the following unit is a present progressive verb phrase ("coding up a storm") * when the following unit is a predicative adjective phrase ("scheduled for another release", "phat", "jealous"). Unfortunately, one kind of adjectival phrase can be formed from the past participle form of the verb in English, which pretty much shoots down any chance for regular-expression-based solutions, at least with any kind of elegance Larry's scheduled for another conference. => "is" (not "has"!) Larry's scheduled another conference. => "has" (not "is"!) It gets worse: "'s" really needs a following noun phrase (without article), but you can make one of these using a past participle! Larry's scheduled conference conflicted with mine. => "'s" (not "has" or "is") This is the sort of thing that drove philosophers to give up on natural language and build lambda calculus. I make this sort of nightmare my problem; natural language via computers is what I study. The "right" solution, Tim, is probably a stochastic parser that would decide what the most likely handling is for the constituent following the 's. That's a pretty neat project -- I can point you to some links if you like -- but I doubt that's really what you want. It's probably less work to design a mini-script that shows you each context and presents to you the choices (you type "'", "'h", or "i") and it rewrites them. Incidentally, contractions are information-losing -- it's much easier to go the other way with a script if you should ever need to. good luck, jeremy who really should be working on a parser this very minute Tim Maher wrote: >Dudes, > >I'm getting complaints from some early reviewers of my book >about all the "contractions" I'm using in my writing! >So last night I set out to write a Perl script to make changes >like the following: > > That's => That is > He's => He is > They're => They are > We're => We are > >Then I realized that the 's ending usually needs replacement by >"is", so I tried > > "'s" => ' is' >which doesn't quite work, because of the undesirability of changing > > Larry's hat => Larry is hat > >After making an exception for that case, I found other complications, >such as > > wouldn't => would not > can't => can not > >These follow different rules, because the 'wouldn' loses its 'n', but the >'can' doesn't! > >So at that point I realized that this is a bigger problem than I first >thought, and decided to look for a solution on CPAN. Searching for >"contractions" didn't turn up anything relevant, so now I'm wondering if >anybody knows of a module that will do this job -- convert a standard set of English >contractions into their expanded forms. > >Can't y'all gimme the help I'm searchin' for? > >-Tim >*------------------------------------------------------------* >| Tim Maher (206) 781-UNIX (866) DOC-PERL (866) DOC-UNIX | >| tim(AT)Consultix-Inc.Com TeachMeUnix.Com TeachMePerl.Com | >*+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-* >| UNIX Fundamentals Class: 11/10-13 Perl Class: 12/01-05 | >| Watch for my Book: "Minimal Perl for Shell Programmers" | >*------------------------------------------------------------* >_____________________________________________________________ >Seattle Perl Users Group Mailing List >POST TO: spug-list@mail.pm.org http://spugwiki.perlocity.org >ACCOUNT CONFIG: http://mail.pm.org/mailman/listinfo/spug-list >MEETINGS: 3rd Tuesdays, U-District, Seattle WA >WEB PAGE: http://www.seattleperl.org > > > From creede at penguinsinthenight.com Sun Oct 26 20:28:38 2003 From: creede at penguinsinthenight.com (Creede Lambard) Date: Mon Aug 2 21:37:11 2004 Subject: SPUG: Software to expand contractions? In-Reply-To: <3F9C7887.2080302@earthlink.net> References: <20031027005412.14309.qmail@web80605.mail.yahoo.com> <3F9C7887.2080302@earthlink.net> Message-ID: <1067221718.20722.16.camel@boris> On Sun, 2003-10-26 at 17:44, Tom Legrady wrote: > he's == he has ???? Can you provide an example? Everybody sing! He's got the whole world . . . in his hands . . . -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: This is a digitally signed message part Url : http://mail.pm.org/pipermail/spug-list/attachments/20031026/cce7dd92/attachment.bin From mathin at mathin.com Mon Oct 27 09:45:04 2003 From: mathin at mathin.com (Dan Ebert) Date: Mon Aug 2 21:37:11 2004 Subject: SPUG: Software to expand contractions? In-Reply-To: <20031027005412.14309.qmail@web80605.mail.yahoo.com> References: <20031027005412.14309.qmail@web80605.mail.yahoo.com> Message-ID: <1067269503.13878.7.camel@algernon.lan.enic.cc> Since we're on a grammar thread ... that should be 'fewer words to read.' Less is used for a matter of degree or with items like these: add less water (but fewer water molecules) have less money (but fewer dollars) I think the rule is something to do with the plural (use fewer with a pluralized word) but am not sure. (Sorry, one of my pet peeves are the signs at the grocery checkouts that say '10 items or less.') :) Dan. On Sun, 2003-10-26 at 16:54, Stuart Poulin wrote: > 's is also a contraction for "has". > i..e "It's been proven" > > "He's" could be "He is" or "He has" depending on context. > > I'd say keep the contractions in - less words to read. > > > > Tim Maher wrote: > > Dudes, > > I'm getting complaints from some early reviewers of my book > about all the "contractions" I'm using in my writing! > So last night I set out to write a Perl script to make changes > like the following: > > That's => That is > He's => He is > They're => They are > We're => We are > > Then I realized that the 's ending usually needs replacement > by > "is", so I tried > > "'s" => ' is' > > ______________________________________________________________________ > Do you Yahoo!? > Exclusive Video Premiere - Britney Spears > > ______________________________________________________________________ > _____________________________________________________________ > Seattle Perl Users Group Mailing List > POST TO: spug-list@mail.pm.org http://spugwiki.perlocity.org > ACCOUNT CONFIG: http://mail.pm.org/mailman/listinfo/spug-list > MEETINGS: 3rd Tuesdays, U-District, Seattle WA > WEB PAGE: http://www.seattleperl.org > From christopher.w.cantrall at boeing.com Mon Oct 27 10:38:59 2003 From: christopher.w.cantrall at boeing.com (Cantrall, Christopher W) Date: Mon Aug 2 21:37:11 2004 Subject: SPUG: Software to expand contractions? Message-ID: You could use a dispatch table of sorts. This let's you take care of the easy substitutions and worry about the is/has/possesive hard ones later. %substitutions{ can't => can not, won't => will not, isn't => is not, shouldn't => should not, wouldn't => would not, wasn't => was not, they're => they are, we're => we are, I'm => I am, I'll => I will, }; Of course, these will need to be properly quoted, and the apostrophes properly escaped, but it's Monday morning and I know I'll foul that up if I try before my first coffee. Good luck, I love the book so far. ____________________________________________ Chris Cantrall Structural Engineer, 777 Fuselage, Boeing Christopher.W.Cantrall@Boeing.com chris@cantrall.org http://perlmonks.org/index.pl?node=Louis_Wu http://spugwiki.perlocity.org/index.cgi?LouisWu > -----Original Message----- > From: Tim Maher [mailto:tim@consultix-inc.com] > Sent: Saturday, October 25, 2003 10:43 AM > To: spug-list@pm.org > Cc: Damian Conway > Subject: SPUG: Software to expand contractions? > > > Dudes, > > I'm getting complaints from some early reviewers of my book > about all the "contractions" I'm using in my writing! > So last night I set out to write a Perl script to make changes > like the following: > > That's => That is > He's => He is > They're => They are > We're => We are > > Then I realized that the 's ending usually needs replacement by > "is", so I tried > > "'s" => ' is' > which doesn't quite work, because of the undesirability of changing > > Larry's hat => Larry is hat > > After making an exception for that case, I found other complications, > such as > > wouldn't => would not > can't => can not > > These follow different rules, because the 'wouldn' loses its > 'n', but the > 'can' doesn't! > > So at that point I realized that this is a bigger problem than I first > thought, and decided to look for a solution on CPAN. Searching for > "contractions" didn't turn up anything relevant, so now I'm > wondering if > anybody knows of a module that will do this job -- convert a > standard set of English > contractions into their expanded forms. > > Can't y'all gimme the help I'm searchin' for? > > -Tim > *------------------------------------------------------------* > | Tim Maher (206) 781-UNIX (866) DOC-PERL (866) DOC-UNIX | > | tim(AT)Consultix-Inc.Com TeachMeUnix.Com TeachMePerl.Com | > *+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-* > | UNIX Fundamentals Class: 11/10-13 Perl Class: 12/01-05 | > | Watch for my Book: "Minimal Perl for Shell Programmers" | > *------------------------------------------------------------* > _____________________________________________________________ > Seattle Perl Users Group Mailing List > POST TO: spug-list@mail.pm.org http://spugwiki.perlocity.org > ACCOUNT CONFIG: http://mail.pm.org/mailman/listinfo/spug-list > MEETINGS: 3rd Tuesdays, U-District, Seattle WA > WEB PAGE: http://www.seattleperl.org > > From christopher.w.cantrall at BOEING.COM Mon Oct 27 11:13:13 2003 From: christopher.w.cantrall at BOEING.COM (Cantrall, Christopher W) Date: Mon Aug 2 21:37:11 2004 Subject: SPUG: Software to expand contractions? Message-ID: And you can build a list of the contration-like words in your book automatically. #!/usr/bin/perl -wln /\b(\w+[']\w+)\b/; print "$1" if $1; It'll print all of the words which contain apostrophes, so you'll get more than just contractions, but it's quick. ... BTW, for some reason I can't seem to get this to work as a one-liner, but I think that's because my shell-fu is weak. If you're morbidly curious: cwc9144@esg2776:<45> perl -wln -e'/\b(\w+\'\w+)\b/; print "$1" if $1;' file /usr/bin/ksh: 0403-057 Syntax error: `)' is not expected. __________________________________________ Christopher Cantrall Structural Engineer, 777 Body Join phone: 425-266-2936 Christopher.W.Cantrall@Boeing.com > -----Original Message----- > From: Cantrall, Christopher W > Sent: Monday, October 27, 2003 8:39 AM > To: Tim Maher; spug-list@pm.org > Cc: Damian Conway > Subject: RE: SPUG: Software to expand contractions? > > > You could use a dispatch table of sorts. This let's you take > care of the easy substitutions and worry about the > is/has/possesive hard ones later. > > %substitutions{ > can't => can not, > won't => will not, > isn't => is not, > shouldn't => should not, > wouldn't => would not, > wasn't => was not, > they're => they are, > we're => we are, > I'm => I am, > I'll => I will, > }; > > Of course, these will need to be properly quoted, and the > apostrophes properly escaped, but it's Monday morning and I > know I'll foul that up if I try before my first coffee. > > Good luck, I love the book so far. > > ____________________________________________ > Chris Cantrall > Structural Engineer, 777 Fuselage, Boeing > Christopher.W.Cantrall@Boeing.com > chris@cantrall.org > http://perlmonks.org/index.pl?node=Louis_Wu > http://spugwiki.perlocity.org/index.cgi?LouisWu > > > > -----Original Message----- > > From: Tim Maher [mailto:tim@consultix-inc.com] > > Sent: Saturday, October 25, 2003 10:43 AM > > To: spug-list@pm.org > > Cc: Damian Conway > > Subject: SPUG: Software to expand contractions? > > > > > > Dudes, > > > > I'm getting complaints from some early reviewers of my book > > about all the "contractions" I'm using in my writing! > > So last night I set out to write a Perl script to make changes > > like the following: > > > > That's => That is > > He's => He is > > They're => They are > > We're => We are > > > > Then I realized that the 's ending usually needs replacement by > > "is", so I tried > > > > "'s" => ' is' > > which doesn't quite work, because of the undesirability of changing > > > > Larry's hat => Larry is hat > > > > After making an exception for that case, I found other > complications, > > such as > > > > wouldn't => would not > > can't => can not > > > > These follow different rules, because the 'wouldn' loses its > > 'n', but the > > 'can' doesn't! > > > > So at that point I realized that this is a bigger problem > than I first > > thought, and decided to look for a solution on CPAN. Searching for > > "contractions" didn't turn up anything relevant, so now I'm > > wondering if > > anybody knows of a module that will do this job -- convert a > > standard set of English > > contractions into their expanded forms. > > > > Can't y'all gimme the help I'm searchin' for? > > > > -Tim > > *------------------------------------------------------------* > > | Tim Maher (206) 781-UNIX (866) DOC-PERL (866) DOC-UNIX | > > | tim(AT)Consultix-Inc.Com TeachMeUnix.Com TeachMePerl.Com | > > *+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-* > > | UNIX Fundamentals Class: 11/10-13 Perl Class: 12/01-05 | > > | Watch for my Book: "Minimal Perl for Shell Programmers" | > > *------------------------------------------------------------* > > _____________________________________________________________ > > Seattle Perl Users Group Mailing List > > POST TO: spug-list@mail.pm.org http://spugwiki.perlocity.org > > ACCOUNT CONFIG: http://mail.pm.org/mailman/listinfo/spug-list > > MEETINGS: 3rd Tuesdays, U-District, Seattle WA > > WEB PAGE: http://www.seattleperl.org > > > > > _____________________________________________________________ > Seattle Perl Users Group Mailing List > POST TO: spug-list@mail.pm.org http://spugwiki.perlocity.org > ACCOUNT CONFIG: http://mail.pm.org/mailman/listinfo/spug-list > MEETINGS: 3rd Tuesdays, U-District, Seattle WA > WEB PAGE: http://www.seattleperl.org > > From jmates at sial.org Mon Oct 27 11:22:37 2003 From: jmates at sial.org (Jeremy Mates) Date: Mon Aug 2 21:37:11 2004 Subject: SPUG: Re: Software to expand contractions? In-Reply-To: References: Message-ID: <20031027172237.GA50471@darkness.sial.org> * Cantrall, Christopher W > BTW, for some reason I can't seem to get this to work as a one-liner, > but I think that's because my shell-fu is weak. If you're morbidly > curious: > > cwc9144@esg2776:<45> perl -wln -e'/\b(\w+\'\w+)\b/; print "$1" if $1;' file > /usr/bin/ksh: 0403-057 Syntax error: `)' is not expected. To quote ' inside '' in the shell requires the following: echo 'cats' echo 'cat'\''s' From tim at consultix-inc.com Mon Oct 27 18:29:26 2003 From: tim at consultix-inc.com (Tim Maher) Date: Mon Aug 2 21:37:11 2004 Subject: SPUG: Here's my de-contraction-ating program Message-ID: <20031027162926.A2425@timji.consultix-inc.com> NOTE: I thought I submitted this post over an hour ago, but it hasn't appeared, so maybe I didn't. Here it is again (sortof). -Tim > On Sun, Oct 26, 2003 at 05:53:10PM -0800, Jeremy G Kahn wrote: > > Yikes! What an exhaustive analysis! Thanks for documenting > the problem so thoroughly. I will *never* use a contraction > again! I dashed off the following program this morning (WARNING: before any caffeine!), but it seems to work, for my writing at least. Note that it depends on "ispell" to prompt for manual corrections in the ambiguous cases, which simplifies the script considerably. But beware, YMMV! -Tim *------------------------------------------------------------* | Tim Maher (206) 781-UNIX (866) DOC-PERL (866) DOC-UNIX | | tim(AT)Consultix-Inc.Com TeachMeUnix.Com TeachMePerl.Com | *+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-* | UNIX Fundamentals Class: 11/10-13 Perl Class: 12/01-05 | | Watch for my Book: "Minimal Perl for Shell Programmers" | *------------------------------------------------------------* #! /usr/bin/perl -wlp -s # Usage: $0 [ -s ] [-debug[=23]] F -debug # for on-screen examination # Usage: $0 [ -s ] [-debug[=23]] F > F2; ispell F2; mv F2 F # to change file #########################################################+ # Copyright 1997-2003, Tim Maher. All Rights Reserved #+ # POB 70563, Seattle WA 98107 USA tim@consultix-inc.com #+ #########################################################+ # -s: enables processing of "'s" endings; # they're replaced by " ${prefix}is", to encourage hand editing # Tricky to handle automatically, because "Let's" means "Let us", # "Larry's got it" means "Larry has got it", etc. our($debug,$s); # makes switches "optional"; suppresses warning if missing BEGIN { ! defined $debug and $debug = 0; # 'cuz used in number ">" # words missing from contractions are lower-case, so z # not Z to get better suggestions from ispell $prefix = 'z'; # Set to process those ending in "'s", other than "It's" $s_okay = defined $s; # $prefix causes "I'd" to be replaced by "I ${prefix}would"; # Triggers ispell to suggest "would", and lets user notice # problem and correct to "I had", etc., if necessary $on = $off = ""; if ($debug) { # for visible flagging of changes $on = -t 1 ? `tput smso` : "{["; # terminal vs. file $off = -t 1 ? `tput rmso` : "]}"; } $MARKER{e} = $MARKER{c} = ""; # to identify proessing type in debugging messages if ( $debug > 1 ) { $MARKER{e} = 'Ending: '; $MARKER{c} = 'Contraction: '; } # Maintainer: Mark word "X" in replacement as # "?X" to flag as needing author's attention, # when there are multiple possibilities for # missing word. ("That's" -> "That is", "that was", etc.) %endings = ( "s" => '?is', # Can't differentiate from possessive "d" => '?would', # could also be had, did, etc. "ll" => 'will', "m" => 'am', "re" => 'are', "re" => 'are', "t" => 'not', "t" => 'not', "ve" => 'have', ); %contractions = ( # NOTE: "He'll, She'll, They'll" handled through %endings # "it's" handled as exception, below # "it's" => 'it is', # Never means possessive, despite common mistyping "that's" => 'that ?is', "there's" => 'there ?is', "he's" => 'he ?is', "here's" => 'here is', "they're" => 'they are', # Whose great idea was won't? Handled as exceptional case # "won't" => 'will not', ); } $old = $_; # Remember original # Can't tell possessives like "X's" from "is" case, # so skip them by explicitly avoiding matches with " 's " if requested # For processing of possessives/contractions ending in "'s", use -s switch $no_s_regex = '[a-rt-z]'; $s_regex = '[a-z]'; $single_char_ending = $s_okay ? $s_regex : $no_s_regex; # This one don't need no stinking rule-based processing! s/\b (i)t's \b/$on$1t is$off/ixg ; if ( # FORMAT: if ( s/RE/computed replacement/e ) { report stuff } s/ \b (\w+) ' ($single_char_ending | [a-z]{2,}) \b / $match = $&; # remember, so can do other matches without trashing $part1 = $1; # remember, so can do other matches without trashing $part2 = $2; # remember, so can do other matches without trashing $debug > 2 and warn "Line $.: 1: $part1, 2: $part2\n"; $debug > 1 and warn "Match: [$match]\n"; if ( $match =~ m|^(c)an't$|i ) { # this is exceptional case $debug > 1 and warn "Matched \"can't\" case\n"; $replacement = $1 . 'an not' ; } elsif ( $match =~ m|^(w)on't$|i ) { # exceptional case $debug > 1 and warn "Matched \"won't\" case\n"; $replacement = $1 . 'ill not' ; } elsif ( defined $endings{$part2} ) { $debug > 1 and warn "Processing ending of '$endings{$part2}'\n"; # remove "n't" in "haven't" before adding " not", etc. $chop = $part1 =~ m|n$| ? 1 : 0 ; $replacement = $MARKER{e} . substr ($part1, 0, (( length $part1) - $chop ) ) . " " . $endings{$part2} ; } elsif ( defined $contractions{$match} ) { warn "Processing contraction for $match\n"; $replacement = "$MARKER{c}$contractions{$match}" ; $part1 =~ m|^[A-Z]| and # match case of original $replacement = "\l$replacement"; } else { $debug > 1 and warn "Skipping $match\n"; $replacement = $match ; } # Change ? to prefix to get ispell's attention and # trigger appropriate correcton suggestions $replacement =~ s|\?|$prefix|g; $on . $replacement . $off # assert replacement value /xegi ) { # Following only shows last sub of group in same record, but # that's good enough for debugging # Reverse-video highlighting of substitutions on screen (from # -debug) actually seems sufficient now $debug > 1 and warn "Old string: $old\n"; $debug > 1 and warn "Changed to New string: $replacement\n"; $debug > 1 and warn "New string: $_\n"; } -Tim *------------------------------------------------------------* | Tim Maher (206) 781-UNIX (866) DOC-PERL (866) DOC-UNIX | | tim(AT)Consultix-Inc.Com TeachMeUnix.Com TeachMePerl.Com | *+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-* | UNIX Fundamentals Class: 11/10-13 Perl Class: 12/01-05 | | Watch for my Book: "Minimal Perl for Shell Programmers" | *------------------------------------------------------------* From mathin at mathin.com Mon Oct 27 10:07:49 2003 From: mathin at mathin.com (Dan Ebert) Date: Mon Aug 2 21:37:11 2004 Subject: SPUG: Software to expand contractions? In-Reply-To: <20031027160514.GB449@wokkil.pair.com> References: <20031027005412.14309.qmail@web80605.mail.yahoo.com> <1067269503.13878.7.camel@algernon.lan.enic.cc> <20031027160514.GB449@wokkil.pair.com> Message-ID: <1067270869.13878.11.camel@algernon.lan.enic.cc> You know, I thought about that and couldn't decide ... not sure which is correct because there 'are' signs ... On Mon, 2003-10-27 at 08:05, Asim Jalis wrote: > On Mon, Oct 27, 2003 at 07:45:04AM -0800, Dan Ebert wrote: > > (Sorry, one of my pet peeves are the signs at the grocery > > checkouts that say '10 items or less.') > > Okay, since we're talking about grammar, I believe that should be > "one of my pet peeves IS" rather than "one of my pet peeves ARE." > > Wait, did I just get trolled? > > > Asim From wildwood_players at yahoo.com Tue Oct 28 09:29:32 2003 From: wildwood_players at yahoo.com (Richard Wood) Date: Mon Aug 2 21:37:11 2004 Subject: SPUG: Software to expand contractions? In-Reply-To: <1067269503.13878.7.camel@algernon.lan.enic.cc> Message-ID: <20031028152932.85681.qmail@web11501.mail.yahoo.com> I know this thread died last night but I wanted to add my one more thing. I was introduced to a book that I find very valuable called "BUGS in Writing" (A Guide to Debugging Your Prose), by Lyn Dupre, Published by Addison Wesley ISBN 020137921X. $19.95 US It deals with about 150 topics such as: Shall versus Will So, So that, Such that Like versus Such as Blocks: Theorems, Proofs, Lemmas and Contractions Each topic has an explanation or discussion then examples. Here is what is said about Contractions: "Although contractions (terms formed of multiple words, in which missing letters are signified by an apostrophe) are respectable terms in casual writing (and in poetry), because they are part of our spoken language, they are out of place in formal writing. I advise you to strive for formal writing that is interesting and amusing, yet still is styled impeccably. Generally speaking, contractions are unnecessarily casual, Most publishers of textbooks an journal articles do not permit contractions." Submitted in a most impeccable manner, Rich Wood --- Dan Ebert wrote: > > Since we're on a grammar thread ... that should be > 'fewer words to > read.' Less is used for a matter of degree or with > items like these: > > add less water (but fewer water molecules) > have less money (but fewer dollars) > > I think the rule is something to do with the plural > (use fewer with a > pluralized word) but am not sure. > > (Sorry, one of my pet peeves are the signs at the > grocery checkouts that > say '10 items or less.') > > :) > > Dan. > > On Sun, 2003-10-26 at 16:54, Stuart Poulin wrote: > > 's is also a contraction for "has". > > i..e "It's been proven" > > > > "He's" could be "He is" or "He has" depending on > context. > > > > I'd say keep the contractions in - less words to > read. > > > > > > > > Tim Maher wrote: > > > > Dudes, > > > > I'm getting complaints from some early > reviewers of my book > > about all the "contractions" I'm using in > my writing! > > So last night I set out to write a Perl > script to make changes > > like the following: > > > > That's => That is > > He's => He is > > They're => They are > > We're => We are > > > > Then I realized that the 's ending usually > needs replacement > > by > > "is", so I tried > > > > "'s" => ' is' > > > > > ______________________________________________________________________ > > Do you Yahoo!? > > Exclusive Video Premiere - Britney Spears > > > > > ______________________________________________________________________ > > > _____________________________________________________________ > > Seattle Perl Users Group Mailing List > > POST TO: spug-list@mail.pm.org > http://spugwiki.perlocity.org > > ACCOUNT CONFIG: > http://mail.pm.org/mailman/listinfo/spug-list > > MEETINGS: 3rd Tuesdays, U-District, Seattle WA > > WEB PAGE: http://www.seattleperl.org > > > _____________________________________________________________ > Seattle Perl Users Group Mailing List > POST TO: spug-list@mail.pm.org > http://spugwiki.perlocity.org > ACCOUNT CONFIG: > http://mail.pm.org/mailman/listinfo/spug-list > MEETINGS: 3rd Tuesdays, U-District, Seattle WA > WEB PAGE: http://www.seattleperl.org > ===== Richard O. Wood Wildwood IT Consultants, Inc. wildwood_players@yahoo.com 425.281.1914 mobile 206.544.9885 desk __________________________________ Do you Yahoo!? Exclusive Video Premiere - Britney Spears http://launch.yahoo.com/promos/britneyspears/ From MichaelRWolf at att.net Tue Oct 28 23:52:08 2003 From: MichaelRWolf at att.net (Michael R. Wolf) Date: Mon Aug 2 21:37:11 2004 Subject: SPUG: defaulting a value In-Reply-To: <20031027162926.A2425@timji.consultix-inc.com> (Tim Maher's message of "Mon, 27 Oct 2003 16:29:26 -0800") References: <20031027162926.A2425@timji.consultix-inc.com> Message-ID: Tim Maher writes: > ! defined $debug and $debug = 0; # 'cuz used in number ">" Somehows the following feel better to my English ears, even though they're DeMorgan Perl equivalents: defined $debug or $debug = 0; $debug = 0 if !defined $debug; $debug = 0 unless defined $debug; But I've also seen the following to set a default. $page_width ||= 80; Of course, it doesn't differentiate between a defined zero as different from undefined. Anyone remember the status of // as an or-ish operator? If's it's available pre-Perl6, then the following would be my suggestion for defaulting an undefined value, but preserving 0 (not necessary in this case, but is necessary in the general case): $debug //= 0; -- Michael R. Wolf All mammals learn by playing! MichaelRWolf@att.net From MichaelRWolf at att.net Wed Oct 29 00:00:41 2003 From: MichaelRWolf at att.net (Michael R. Wolf) Date: Mon Aug 2 21:37:11 2004 Subject: SPUG: html->pdf conversion? In-Reply-To: <25160AB2660F8B449892B0EB9C29C165C1F907@ex-sea-is2.cobaltgroup.com> (Jerome O'neil's message of "Wed, 22 Oct 2003 11:18:01 -0700") References: <25160AB2660F8B449892B0EB9C29C165C1F907@ex-sea-is2.cobaltgroup.com> Message-ID: "O'neil, Jerome" writes: > On Wed, Oct 22, 2003 at 10:22:25AM -0700, O'neil, Jerome wrote: [...] > The SDK API's are described through an IDL, so they are language > independent. They provide bindings for Java, OOBasic, and C++. You get > object representations of all the OO stuff, including draw, spreadsheet, and > document. While there isn't a Perl language binding, I'm sure someone, > somewhere could provide an XS implementation over the C++ stuff. use Inline; ???? Or a subclass thereof? -- Michael R. Wolf All mammals learn by playing! MichaelRWolf@att.net From MichaelRWolf at att.net Wed Oct 29 00:04:15 2003 From: MichaelRWolf at att.net (Michael R. Wolf) Date: Mon Aug 2 21:37:11 2004 Subject: SPUG: Login Page and Cookies In-Reply-To: <6906BE0C-05F3-11D8-BF26-0003937B36CA@closehauled.com> (Sam Carpenter's message of "Fri, 24 Oct 2003 00:26:40 -0700") References: <6906BE0C-05F3-11D8-BF26-0003937B36CA@closehauled.com> Message-ID: Sam Carpenter writes: > I am just getting started with Perl (switching from Java and .NET) Yeah! Good for you! Welcome..... I'm sure folks here would be interested in why you're switching, either now, or when you get a chance to get more perspective on the differences. -- Michael R. Wolf All mammals learn by playing! MichaelRWolf@att.net From david.dyck at fluke.com Wed Oct 29 00:32:07 2003 From: david.dyck at fluke.com (David Dyck) Date: Mon Aug 2 21:37:11 2004 Subject: SPUG: defaulting a value In-Reply-To: References: <20031027162926.A2425@timji.consultix-inc.com> Message-ID: On Tue, 28 Oct 2003 at 21:52 -0800, Michael R. Wolf ...: > Anyone remember the status of // as an or-ish operator? If's it's > available pre-Perl6, then the following would be my suggestion for > defaulting an undefined value, but preserving 0 (not necessary in this > case, but is necessary in the general case): > > $debug //= 0; perldelta.pod from perl, v5.9.0 has: NAME perldelta - what is new for perl v5.9.0 DESCRIPTION This document describes differences between the 5.8.0 release and the 5.9.0 release. ....... Defined-or operators A new operator "//" (defined-or) has been implemented. The following statement: $a // $b is merely equivalent to defined $a ? $a : $b and $c //= $d; can be used instead of $c = $d unless defined $c; This operator has the same precedence and associativity as "||". It has a low-precedence counterpart, "err", which has the same precedence and associativity as "or". Special care has been taken to ensure that those operators Do What You Mean while not breaking old code, but some edge cases involving the empty regular expression may now parse differently. See perlop for details. From sthoenna at efn.org Wed Oct 29 00:39:00 2003 From: sthoenna at efn.org (Yitzchak Scott-Thoennes) Date: Mon Aug 2 21:37:11 2004 Subject: SPUG: defaulting a value In-Reply-To: References: <20031027162926.A2425@timji.consultix-inc.com> Message-ID: <20031029063859.GA3720@efn.org> On Tue, Oct 28, 2003 at 09:52:08PM -0800, "Michael R. Wolf" wrote: > Anyone remember the status of // as an or-ish operator? If's it's > available pre-Perl6, then the following would be my suggestion for > defaulting an undefined value, but preserving 0 (not necessary in this > case, but is necessary in the general case): > > $debug //= 0; //, //=, and err operators are in 5.9.0. H.M.Brand has a patch to also implement them for earlier perls (back to 5.8.0 maybe?) that he updates for each new release. The latest (for 5.8.2-RC1) is on CPAN at: http://www.cpan.org/authors/id/H/HM/HMBRAND/dor-5.8.2-rc1.diff From MichaelRWolf at att.net Wed Oct 29 07:02:52 2003 From: MichaelRWolf at att.net (Michael R. Wolf) Date: Mon Aug 2 21:37:11 2004 Subject: SPUG: defaulting a value In-Reply-To: <20031028233322.A6829@timji.consultix-inc.com> (Tim Maher's message of "Tue, 28 Oct 2003 23:33:22 -0800") References: <20031027162926.A2425@timji.consultix-inc.com> <20031028233322.A6829@timji.consultix-inc.com> Message-ID: Tim Maher/CONSULTIX writes: [...] > TMTOWTDI! In fact, TMTFWTDI, for some definition of F (e.g. four). :-) -- Michael R. Wolf All mammals learn by playing! MichaelRWolf@att.net From pdarley at kinesis-cem.com Wed Oct 29 14:39:42 2003 From: pdarley at kinesis-cem.com (Peter Darley) Date: Mon Aug 2 21:37:11 2004 Subject: SPUG: Relative paths in Mod_Perl 2 Message-ID: Folks, I'm looking for suggestions for a problem I'm having. In my code under mod_perl before 2 I was doing a use lib '../Modules' so different virtual servers would be able to have different versions of their modules, so I can have different development trees active on the same server. Under Mod_Perl 2.0 it doesn't chdir into the script directory, so I can't do that any more. I want to just build an absolute directory for the use lib, but I cant find out how to get the directory of the script from Mod_Perl or Apache::Registry or anything. Any suggestions? Thanks, Peter Darley From lmzaldivar at mac.com Thu Oct 30 17:27:19 2003 From: lmzaldivar at mac.com (Luis Medrano) Date: Mon Aug 2 21:37:11 2004 Subject: SPUG: mode_perl Message-ID: <8029650.1067556439623.JavaMail.lmzaldivar@mac.com> List, Question, I have a web server with multiple domains and I trying to do the following using mode_perl: http://domain1.com/perl pull a web page and add the word perl which is on the url or if I have http://domain.com/linux put the word linux on the webpage. My question is how I can do this?.. Thanks, Luis From jaygray at scn.org Fri Oct 31 14:47:23 2003 From: jaygray at scn.org (Jay Gray) Date: Mon Aug 2 21:37:11 2004 Subject: SPUG: mode_perl In-Reply-To: <8029650.1067556439623.JavaMail.lmzaldivar@mac.com> Message-ID: Hi, Luis! Good to 'see' you again. ;-) I'll talk to you off-line, to catch up on old times. Talking about old times, what you are asking is 'close' to what we did at InfoSpace together. In your specific case, you should lift a 'public domain' solution from the Internet; the goal is to show your solution is clearly independent of anything we did at INSP. Am I being paranoid about you violating your 'non-compete agreement'? Maybe a little... but it's better to avoid lawyers at all costs. Let us know what you find (and where you find it). Peace, Jay Gray On Thu, 30 Oct 2003, Luis Medrano wrote: > List, > > Question, > > I have a web server with multiple domains and I trying to do the following using mode_perl: > > http://domain1.com/perl > > pull a web page and add the word perl which is on the url or if I have http://domain.com/linux put the word linux on the webpage. My question is how I can do this?.. > > Thanks, > Luis > > _____________________________________________________________ > Seattle Perl Users Group Mailing List > POST TO: spug-list@mail.pm.org http://spugwiki.perlocity.org > ACCOUNT CONFIG: http://mail.pm.org/mailman/listinfo/spug-list > MEETINGS: 3rd Tuesdays, U-District, Seattle WA > WEB PAGE: http://www.seattleperl.org > > From alan at ufies.org Fri Oct 31 15:43:22 2003 From: alan at ufies.org (Alan) Date: Mon Aug 2 21:37:11 2004 Subject: SPUG: mode_perl In-Reply-To: <8029650.1067556439623.JavaMail.lmzaldivar@mac.com> References: <8029650.1067556439623.JavaMail.lmzaldivar@mac.com> Message-ID: <20031031214320.GA22666@ufies.org> On Thu, Oct 30, 2003 at 03:27:19PM -0800, Luis Medrano wrote: > List, > > Question, > > I have a web server with multiple domains and I trying to do the following using mode_perl: > > http://domain1.com/perl > > pull a web page and add the word perl which is on the url or if I have http://domain.com/linux put the word linux on the webpage. My question is how I can do this?.. If I remember right, you use something like this: # Have apache put the /words url under control of the My::Words perl # module. SetHandler perl-script PerlHandler My::Words # In the My::Words module: sub handler { my $r = shift; # send the page headers $r->content_type('text/html'); $r->send_http_header; # get the path that is passed to this module my $words = $r->path_info(); $r->print($words); } Basically if you have /words under the control of mod_perl, when you go to the url of http://server.com/words/perl, everything past /words can be retrieved with the path_info() function, and then you can do whatever you want with it. Note the above code should work, but hasn't been tested. alan -- Alan - http://arcterex.net -------------------------------------------------------------------- "There are only 3 real sports: bull-fighting, car racing and mountain climbing. All the others are mere games." -- Hemingway