From westerman at purdue.edu Mon Feb 14 07:00:35 2011 From: westerman at purdue.edu (Rick Westerman) Date: Mon, 14 Feb 2011 10:00:35 -0500 (EST) Subject: [Purdue-pm] PM meeting tomorrow, Feb. 15th In-Reply-To: <1368599726.38769.1297695594684.JavaMail.root@mailhub016.itcs.purdue.edu> Message-ID: <1054821657.38771.1297695635497.JavaMail.root@mailhub016.itcs.purdue.edu> The third Tuesday of the month is early! Anyway, PM meeting tomorrow in WSLR 116. Arrive around 11:30 to socialize. Derek may have something to present around noon. If not, I am sure we can come up with something. -- Rick Westerman westerman at purdue.edu Bioinformatics specialist at the Genomics Facility. Phone: (765) 494-0505 FAX: (765) 496-7255 Department of Horticulture and Landscape Architecture 625 Agriculture Mall Drive West Lafayette, IN 47907-2010 Physically located in room S049, WSLR building From derrick at csociety.org Mon Feb 14 07:35:03 2011 From: derrick at csociety.org (derrick) Date: Mon, 14 Feb 2011 10:35:03 -0500 Subject: [Purdue-pm] PM meeting tomorrow, Feb. 15th In-Reply-To: <1054821657.38771.1297695635497.JavaMail.root@mailhub016.itcs.purdue.edu> References: <1054821657.38771.1297695635497.JavaMail.root@mailhub016.itcs.purdue.edu> Message-ID: <4D594BA7.5020005@csociety.org> On 02/14/2011 10:00 AM, Rick Westerman wrote: > The third Tuesday of the month is early! Anyway, PM meeting > tomorrow in WSLR 116. Arrive around 11:30 to socialize. Derek may > have something to present around noon. If not, I am sure we can come > up with something. > Oh, where does the time go? I'll have a few examples of use we can talk about. dsk From gizmo at purdue.edu Mon Feb 14 08:01:18 2011 From: gizmo at purdue.edu (Joe Kline) Date: Mon, 14 Feb 2011 11:01:18 -0500 Subject: [Purdue-pm] PM meeting tomorrow, Feb. 15th In-Reply-To: <1054821657.38771.1297695635497.JavaMail.root@mailhub016.itcs.purdue.edu> References: <1054821657.38771.1297695635497.JavaMail.root@mailhub016.itcs.purdue.edu> Message-ID: <4D5951CE.8060909@purdue.edu> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 I should be able to give a brief talk of the Frozen Perl workshop I attended on Feb. 5th. joe -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.5 (GNU/Linux) Comment: Using GnuPG with Red Hat - http://enigmail.mozdev.org/ iD8DBQFNWVHNb0mzA2gRTpkRAq0fAKCQhFx1tyOVsn+BayiBqmz4VbtjqQCglt8M jAumWmsMfNjWQ3nGTG1aZx0= =zRDc -----END PGP SIGNATURE----- From jacoby at purdue.edu Fri Feb 18 06:16:48 2011 From: jacoby at purdue.edu (Dave Jacoby) Date: Fri, 18 Feb 2011 09:16:48 -0500 Subject: [Purdue-pm] Mark's Travelling Capital Problem Message-ID: <4D5E7F50.4050300@purdue.edu> I wrote code to determine Mark Senn's shortest and longest path using what I thought was the obvious most-remote capital in the lower 48 (Maine) and the obvious method, choosing the closest capital (or the longest, depending on the decision. I think the decision for the longest is sound. I cannot imagine a more convoluted path than longest.png, but I'm seeing problems with the "shortest" graph. Clearly, UT AZ CA NV OR WA would be a better choice than leaving AZ for last. I'm not sure the New England path is optimal, either. Which means I'll have to come up with something better, that recurses more. I don't want to check all possible choices, as that's going to be 48! choices and I want an answer before the sun burns out. But maybe starting out with all 48 and definitely checking through the 5 closest capitals at each time. This will kick up the search time, which right now sits at less than a second on my desktop system. Upon request, I can share my state data and distance algorithm, although I did find both through Google searches. -- Dave Jacoby Address: WSLR S049 Code Maker Mail: jacoby at purdue.edu Purdue University Phone: 765.49.67368 -------------- next part -------------- A non-text attachment was scrubbed... Name: longest.png Type: image/png Size: 51555 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: shortest.png Type: image/png Size: 53651 bytes Desc: not available URL: From gizmo at purdue.edu Fri Feb 18 06:31:14 2011 From: gizmo at purdue.edu (Joe Kline) Date: Fri, 18 Feb 2011 09:31:14 -0500 Subject: [Purdue-pm] Mark's Travelling Capital Problem In-Reply-To: <4D5E7F50.4050300@purdue.edu> References: <4D5E7F50.4050300@purdue.edu> Message-ID: <4D5E82B2.3040903@purdue.edu> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 It took me longer than I thought to find the lat/long for the state capitals. There is a thread on perlmongers that points to Math::Trig for calculating great circle distance. I just haven't made the time to calculate the longest route (the easier of the two I think). Shortest is the tougher one by far. joe -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.5 (GNU/Linux) Comment: Using GnuPG with Red Hat - http://enigmail.mozdev.org/ iD8DBQFNXoKxb0mzA2gRTpkRAi94AJ9chsRcC5HyLBXn61UphBrudjQnWwCfYzs7 H+NNdVrNEL0BVY4BN15DzEc= =l59C -----END PGP SIGNATURE----- From bradley.d.andersen at gmail.com Fri Feb 18 06:57:31 2011 From: bradley.d.andersen at gmail.com (Bradley Andersen) Date: Fri, 18 Feb 2011 09:57:31 -0500 Subject: [Purdue-pm] Mark's Travelling Capital Problem In-Reply-To: <4D5E82B2.3040903@purdue.edu> References: <4D5E7F50.4050300@purdue.edu> <4D5E82B2.3040903@purdue.edu> Message-ID: I haven't even seen this problem, but I will tell you this: I recently needed to find distances between zip codes, and the great circle formula was *helpful*, but not *super* helpful. It seems to break down at short distances. I ended up using those values along with another algo (forget, but could look it up) and weighting them to get good short distances. On Fri, Feb 18, 2011 at 9:31 AM, Joe Kline wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > It took me longer than I thought to find the lat/long for the state > capitals. > > There is a thread on perlmongers that points to Math::Trig for > calculating great circle distance. > > I just haven't made the time to calculate the longest route (the easier > of the two I think). > > Shortest is the tougher one by far. > > joe > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.4.5 (GNU/Linux) > Comment: Using GnuPG with Red Hat - http://enigmail.mozdev.org/ > > iD8DBQFNXoKxb0mzA2gRTpkRAi94AJ9chsRcC5HyLBXn61UphBrudjQnWwCfYzs7 > H+NNdVrNEL0BVY4BN15DzEc= > =l59C > -----END PGP SIGNATURE----- > _______________________________________________ > Purdue-pm mailing list > Purdue-pm at pm.org > http://mail.pm.org/mailman/listinfo/purdue-pm > From mark at ecn.purdue.edu Fri Feb 18 06:58:32 2011 From: mark at ecn.purdue.edu (Mark Senn) Date: Fri, 18 Feb 2011 09:58:32 -0500 Subject: [Purdue-pm] Mark's Travelling Capital Problem In-Reply-To: <4D5E7F50.4050300@purdue.edu> References: <4D5E7F50.4050300@purdue.edu> Message-ID: <3056.1298041112@pier.ecn.purdue.edu> > I think the decision for the longest is sound. I cannot imagine a more > convoluted path than longest.png, but I'm seeing problems with the > "shortest" graph. Clearly, UT AZ CA NV OR WA would be a better choice > than leaving AZ for last. I'm not sure the New England path is > optimal, either. Everyone, Here's a brief statement of the problem. Starting at any state capital in the lower 48 go to the other 47 state capitals visiting each capital only once. Figure out the longest and shortest path. Send your solution, guess, etc., in the form, for example, from: Mark Senn name: states visited in random order path: CADEIN[note: 45 more state abbreviations should go here -mark] Use a unique name for each path submitted. I'll write something up about this. Let me know if you don't want your solution, guess, etc. included in the write-up. -mark From westerman at purdue.edu Fri Feb 18 07:06:25 2011 From: westerman at purdue.edu (Rick Westerman) Date: Fri, 18 Feb 2011 10:06:25 -0500 (EST) Subject: [Purdue-pm] Mark's Travelling Capital Problem In-Reply-To: <3056.1298041112@pier.ecn.purdue.edu> Message-ID: <1359300564.65163.1298041585511.JavaMail.root@mailhub016.itcs.purdue.edu> > > Here's a brief statement of the problem. Starting at any state capital > in the lower 48 go to the other 47 state capitals visiting each > capital > only once. Figure out the longest and shortest path. Great circle (e.g., bird flight)? Direct (e.g., mole tunneling)? Driving distance? Or all three? -- Rick Westerman westerman at purdue.edu Bioinformatics specialist at the Genomics Facility. Phone: (765) 494-0505 FAX: (765) 496-7255 Department of Horticulture and Landscape Architecture 625 Agriculture Mall Drive West Lafayette, IN 47907-2010 Physically located in room S049, WSLR building From mark at ecn.purdue.edu Fri Feb 18 07:15:09 2011 From: mark at ecn.purdue.edu (Mark Senn) Date: Fri, 18 Feb 2011 10:15:09 -0500 Subject: [Purdue-pm] Mark's Travelling Capital Problem In-Reply-To: <4D5E82B2.3040903@purdue.edu> References: <4D5E7F50.4050300@purdue.edu> <4D5E82B2.3040903@purdue.edu> Message-ID: <7245.1298042109@pier.ecn.purdue.edu> > I just haven't made the time to calculate the longest route (the easier > of the two I think). I think finding the longest route and the shortest route are the same amound of work if you do it numerically. If I'm thinking about this right: the shortest route minimizes the path distance. The longest route maximizes the path distance. If you use the negative of the distances between capitals and minimize that I think that will give the longest path. If I'm thinking about this right. Rhetorical question: will this observation help compute the longest and shortest path "at the same time" faster than computing one path and then the other path? -mark From mark at ecn.purdue.edu Fri Feb 18 07:42:29 2011 From: mark at ecn.purdue.edu (Mark Senn) Date: Fri, 18 Feb 2011 10:42:29 -0500 Subject: [Purdue-pm] Mark's Travelling Capital Problem In-Reply-To: <1359300564.65163.1298041585511.JavaMail.root@mailhub016.itcs.purdue.edu> References: <1359300564.65163.1298041585511.JavaMail.root@mailhub016.itcs.purdue.edu> Message-ID: <14754.1298043749@pier.ecn.purdue.edu> > Great circle (e.g., bird flight)? Direct (e.g., mole tunneling)? > Driving distance? > > Or all three? Your choice. I'll be doing at least as the crow flies and the mole digs. GUESS: since the lower 48 are relatively flat (i.e. don't wrap around a sphere much) I'm guessing the solutions for those two will be the same. I don't plan to do driving distance because of garbage in, garbage out problems if bad data is used---if I remember right people in England have driven into the ocean following instructions from their GPS. (A much harder real-life delivery person problem: given a list of addresses find the driving route between them that will take the least time. Take the times people will be home and the traffic into account. :-) I think there also may be issues with the earth not being perfectly round. I plan to ignore that, difference in altitude between cities, etc. Figure it won't change the answer. If I run into problems with great circle distances acting weird at short distances like Bradley wrote about I'll probably just consider latitude and longitude as 2D Cartesian coordinates. I'll shut up now. Thanks for you patience. -mark From jacoby at purdue.edu Fri Feb 18 08:35:14 2011 From: jacoby at purdue.edu (Dave Jacoby) Date: Fri, 18 Feb 2011 11:35:14 -0500 Subject: [Purdue-pm] Mark's Travelling Capital Problem In-Reply-To: <3056.1298041112@pier.ecn.purdue.edu> References: <4D5E7F50.4050300@purdue.edu> <3056.1298041112@pier.ecn.purdue.edu> Message-ID: <4D5E9FC2.4050400@purdue.edu> On 02/18/2011 09:58 AM, Mark Senn wrote: > Here's a brief statement of the problem. Starting at any state capital > in the lower 48 go to the other 47 state capitals visiting each capital > only once. Figure out the longest and shortest path. Send your solution, > guess, etc., in the form, for example, > from: Mark Senn > name: states visited in random order > path: CADEIN[note: 45 more state abbreviations should go here -mark] > Use a unique name for each path submitted. > > I'll write something up about this. Let me know if you don't want your > solution, guess, etc. included in the write-up. It strikes me that having some consistency in the data so that the differences are related to the path-deciding algorithm would make great amounts of sense. In that spirit, here's my data for the state capitals, tab-delimited. Right now, I'm seeing that depth-first is giving me a demonstrably-wrong solution quickly, but working out a breadth-first algorithm that would work is not initially obvious. I used the haversine formula (http://en.wikipedia.org/wiki/Haversine_formula) to determine distances. Certainly it is point-to-point and not equivalent to what you'd do for driving, but that's a much more complex calculation. -- Dave Jacoby Address: WSLR S049 Code Maker Mail: jacoby at purdue.edu Purdue University Phone: 765.49.67368 -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: state_data.txt URL: From bradley.d.andersen at gmail.com Fri Feb 18 08:54:51 2011 From: bradley.d.andersen at gmail.com (Bradley Andersen) Date: Fri, 18 Feb 2011 11:54:51 -0500 Subject: [Purdue-pm] Mark's Travelling Capital Problem In-Reply-To: <4D5E9FC2.4050400@purdue.edu> References: <4D5E7F50.4050300@purdue.edu> <3056.1298041112@pier.ecn.purdue.edu> <4D5E9FC2.4050400@purdue.edu> Message-ID: Here's some general links I used a long time ago; they may be good or not; I haven't looked at them in a while: http://search.cpan.org/~bluefeet/GIS-Distance-0.07/lib/GIS/Distance/Formula/GreatCircle.pm **** http://mathforum.org/library/drmath/view/51879.html **** http://www.scribd.com/doc/2569355/Geo-Distance-Search-with-MySQL http://itouchmap.com/latlong.html http://mathworld.wolfram.com/GreatCircle.html http://www.codecodex.com/wiki/Calculate_Distance_Between_Two_Points_on_a_Globe Those are straight from an email I wrote myself. I don't recall why the emphasis on the mathforum link. I do recall the first link for the perl module gave really fuzzy answers. That module seems a work in progress and falls flat at short distances, as the author himself notes. Attached is the first great circle perl solution I found online that I adapted for my ultimate zip codes++ answer. This code is someone else's but the standard warranty and license stuff is there. it is very old code; surely better ways now. \brad ++ by 'zip codes' i really mean 'pin codes', as i was working out distances between 'cities' in India, and they call their zip codes pin codes. i had a fat db of lat/lon to use, so this script was helpful, and gave better answers than, say, the above-quoted perl module. i worked out an even fatter crosstable of distances between all cities in india. 2011/2/18 Dave Jacoby : > On 02/18/2011 09:58 AM, Mark Senn wrote: >> >> Here's a brief statement of the problem. ?Starting at any state capital >> in the lower 48 go to the other 47 state capitals visiting each capital >> only once. ?Figure out the longest and shortest path. ?Send your solution, >> guess, etc., in the form, for example, >> ? ? from: Mark Senn >> ? ? name: states visited in random order >> ? ? path: CADEIN[note: 45 more state abbreviations should go here -mark] >> Use a unique name for each path submitted. >> >> I'll write something up about this. ?Let me know if you don't want your >> solution, guess, etc. included in the write-up. > > It strikes me that having some consistency in the data so that the > differences are related to the path-deciding algorithm would make great > amounts of sense. In that spirit, here's my data for the state capitals, > tab-delimited. > > Right now, I'm seeing that depth-first is giving me a demonstrably-wrong > solution quickly, but working out a breadth-first algorithm that would work > is not initially obvious. > > I used the haversine formula > (http://en.wikipedia.org/wiki/Haversine_formula) to determine distances. > Certainly it is point-to-point and not equivalent to what you'd do for > driving, but that's a much more complex calculation. > > -- > Dave Jacoby ? ? ? ? ? ? ? ? ? ? ? ? Address: WSLR S049 > Code Maker ? ? ? ? ? ? ? ? ? ? ? ? ?Mail: ? ?jacoby at purdue.edu > Purdue University ? ? ? ? ? ? ? ? ? Phone: ? 765.49.67368 > > _______________________________________________ > Purdue-pm mailing list > Purdue-pm at pm.org > http://mail.pm.org/mailman/listinfo/purdue-pm > -------------- next part -------------- A non-text attachment was scrubbed... Name: distance.pl Type: application/octet-stream Size: 7710 bytes Desc: not available URL: From jacoby at purdue.edu Fri Feb 18 12:47:08 2011 From: jacoby at purdue.edu (Dave Jacoby) Date: Fri, 18 Feb 2011 15:47:08 -0500 Subject: [Purdue-pm] In the spirit of the proposed Perl.Corn suggestion Message-ID: <4D5EDACC.4080608@purdue.edu> http://www.indianalinux.org/ I'm waiting for the announcement of a schedule to decide if it'll be worth my time or just a swag collection opportunity, but this seems like the kind of thing that we as open-source software users should encourage. -- Dave Jacoby Address: WSLR S049 Code Maker Mail: jacoby at purdue.edu Purdue University Phone: 765.49.67368 From mark at purdue.edu Sun Feb 20 13:59:44 2011 From: mark at purdue.edu (Mark Senn) Date: Sun, 20 Feb 2011 16:59:44 -0500 Subject: [Purdue-pm] state capital tour problem Message-ID: <8292.1298239184@pier.ecn.purdue.edu> I decided I'm only going to do the state capitol tour problem in Mathematica and only do distances as the crow flies. Mathematica was able to read curated data off the web with little trouble. The program claims the minimum distance needed to visit all state capitals (starting at one and visiting the other 48 without visiting any twice) is 10,648.5 miles and maximum distance is 70,587.1. See https://engineering.purdue.edu/~mark/state.pdf for the program, order to tour states, and graphics for the tours (I haven't found state outlines on the net that I'm happy with yet, after that's done I'll combine the tour graphics with state outlines. If you know of any high quality state outlines that only show the state outlines and no features smaller that the great lakes let me know. I want a file format that contains lots of detail and can be converted to latitute and longitudes.) -mark From gizmo at purdue.edu Sun Feb 20 20:49:19 2011 From: gizmo at purdue.edu (Joe Kline) Date: Sun, 20 Feb 2011 23:49:19 -0500 Subject: [Purdue-pm] state capital tour problem In-Reply-To: <8292.1298239184@pier.ecn.purdue.edu> References: <8292.1298239184@pier.ecn.purdue.edu> Message-ID: <4D61EECF.1060106@purdue.edu> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 My test runs are rather interesting: Alpha by state name: total: 11.518521713179; miles: 45647.9015493286; km: 73465.131486656 Alpha by capital name: total: 11.8664993743746; miles: 47026.9370206463; km: 75684.5330097609 Now to get a traveling algorithm whipped up... -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAk1h7s0ACgkQb0mzA2gRTpmTeACeJV0kN9jf4GZnpSAab4UKARQu OHoAnRZYTEmf2nBlLRFgYGwlySkqDtpR =gNxF -----END PGP SIGNATURE----- From jacoby.david at gmail.com Sun Feb 20 21:28:46 2011 From: jacoby.david at gmail.com (Dave Jacoby) Date: Mon, 21 Feb 2011 00:28:46 -0500 Subject: [Purdue-pm] state capital tour problem In-Reply-To: <8292.1298239184@pier.ecn.purdue.edu> References: <8292.1298239184@pier.ecn.purdue.edu> Message-ID: How long does that take to generate that list? What I have takes forever. On Sun, Feb 20, 2011 at 16:59, Mark Senn wrote: > I decided I'm only going to do the state capitol tour problem in > Mathematica and only do distances as the crow flies. > > Mathematica was able to read curated data off the web with little trouble. > > The program claims the minimum distance needed to visit all state > capitals (starting at one and visiting the other 48 without visiting any > twice) is 10,648.5 miles and maximum distance is 70,587.1. > > See > ? ?https://engineering.purdue.edu/~mark/state.pdf > for the program, order to tour states, and graphics > for the tours (I haven't found state outlines > on the net that I'm happy with yet, after that's > done I'll combine the tour graphics with state outlines. > If you know of any high quality state outlines that > only show the state outlines and no features smaller > that the great lakes let me know. ?I want a file format > that contains lots of detail and can be converted to > latitute and longitudes.) > > -mark > _______________________________________________ > Purdue-pm mailing list > Purdue-pm at pm.org > http://mail.pm.org/mailman/listinfo/purdue-pm > -- David Jacoby? ?? jacoby.david at gmail.com From mark at ecn.purdue.edu Mon Feb 21 17:02:30 2011 From: mark at ecn.purdue.edu (Mark Senn) Date: Mon, 21 Feb 2011 20:02:30 -0500 Subject: [Purdue-pm] state capital tour problem In-Reply-To: References: <8292.1298239184@pier.ecn.purdue.edu> Message-ID: <23248.1298336550@pier.ecn.purdue.edu> > How long does that take to generate that list? What I have takes forever. The program took 108 seconds to run on a 8 CPU Intel Core i7 920 running at 2.67 GHz using Mathematic 8.0.0.0 on Fedora 14 Linux. I updated https://engineering.purdue.edu/~mark/state.pdf web page with that and some other information. That file shows what a Mathematica notebook looks like with mixed text and code. You may need to reload the page to get the latest version (dated February 21, 2011). -mark From mark at purdue.edu Fri Feb 25 12:29:14 2011 From: mark at purdue.edu (Mark Senn) Date: Fri, 25 Feb 2011 15:29:14 -0500 Subject: [Purdue-pm] smart matching in Perl Message-ID: <10134.1298665754@pier.ecn.purdue.edu> The '~~' is used to do smart matching in Perl. I like smart match. I'm working on a program that needs to run on Perl 5.10 and 5.12 (don't ask). I'd love to use Perl's smart match to do it but that won't work in 5.10. Below is a program to demonstrate two ways of getting an answer. I don't claim either of these are optimal. -mark #!/usr/local/bin/perl @re = ( qr /^a$/, qr /^b$/ ); foreach (qw(a c)) { # In Perl 5.10 here's one way to print if $_ # doesn't match any regular expression in @re: $t = 0; foreach my $re (@re) { if ($_ =~ $re) { $t = 1; last; } } ($t) or print qq/"$_" doesn't match\n/; # Get same results in Perl 5.12: print qq/"$_" doesn't match\n/ unless ($_ ~~ @re); } From westerman at purdue.edu Fri Feb 25 12:41:38 2011 From: westerman at purdue.edu (Rick Westerman) Date: Fri, 25 Feb 2011 15:41:38 -0500 (EST) Subject: [Purdue-pm] smart matching in Perl In-Reply-To: <10134.1298665754@pier.ecn.purdue.edu> Message-ID: <45735819.108071.1298666498930.JavaMail.root@mailhub016.itcs.purdue.edu> ----- Original Message ----- > The '~~' is used to do smart matching in Perl. I like smart match. > > I'm working on a program that needs to run on Perl 5.10 and 5.12 > (don't > ask). I'd love to use Perl's smart match to do it but that won't work > in 5.10. Below is a program to demonstrate two ways of getting an > answer. I don't claim either of these are optimal. -mark use SmartMatch::Sugar; No? -- Rick Westerman westerman at purdue.edu Bioinformatics specialist at the Genomics Facility. Phone: (765) 494-0505 FAX: (765) 496-7255 Department of Horticulture and Landscape Architecture 625 Agriculture Mall Drive West Lafayette, IN 47907-2010 Physically located in room S049, WSLR building From gizmo at purdue.edu Fri Feb 25 17:27:47 2011 From: gizmo at purdue.edu (Joe Kline) Date: Fri, 25 Feb 2011 20:27:47 -0500 Subject: [Purdue-pm] smart matching in Perl In-Reply-To: <10134.1298665754@pier.ecn.purdue.edu> References: <10134.1298665754@pier.ecn.purdue.edu> Message-ID: <4D685713.2080801@purdue.edu> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 02/25/2011 03:29 PM, Mark Senn wrote: > The '~~' is used to do smart matching in Perl. I like smart match. > > I'm working on a program that needs to run on Perl 5.10 and 5.12 (don't > ask). I'd love to use Perl's smart match to do it but that won't work > in 5.10. Below is a program to demonstrate two ways of getting an > answer. I don't claim either of these are optimal. -mark > > #!/usr/local/bin/perl > > @re = ( > qr /^a$/, > qr /^b$/ > ); > (forgot to send to the list...) Mark, which version of 5.10 are you using? There is a bug in 5.10.0 that doesn't handle an array of compiled regexes properly. It was fixed in 5.10.1. That's just a guess on my part (from personal experience) http://perlmonks.com/?node_id=880672 joe -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAk1oVxEACgkQb0mzA2gRTpm/MACfYNVHcx1KZIqOaGJz9kMJkBLq NhUAn2SBNAl4mDKOlseXzgC2IUS2fDHf =bSvP -----END PGP SIGNATURE----- From mark at purdue.edu Sat Feb 26 12:22:20 2011 From: mark at purdue.edu (Mark Senn) Date: Sat, 26 Feb 2011 15:22:20 -0500 Subject: [Purdue-pm] don't use qr//o Message-ID: <4619.1298751740@pier.ecn.purdue.edu> (I'll submit a bug report if this is in the next version of Perl.) #!/usr/bin/perl # # SUMMARY # # Don't use qr//o. # # DETAILS # # This program works as expected. It prints # a # 1 yes # 2 yes # b # 1 yes # 2 yes # c # 1 no # 2 no # # If the # @re = map { qr /$_/ } @re; # line is changed to # @re = map { qr /$_/o } @re; # using # % perl --version # This is perl 5, version 12, subversion 3 (v5.12.3) [cont. on next line] # built for i386-linux-thread-multi # on # % cat /etc/fedora-release # Fedora release 14 (Laughlin) # % uname -a # Linux localhost.localdomain [cont. on next line] # 2.6.35.6-48.fc14.i686 #1 SMP [cont. on next line] # Fri Oct 22 15:34:36 UTC 2010 i686 i686 i386 GNU/Linux # the program prints # a # 1 yes # 2 yes # b # 1 no # 2 no # c # 1 no # 2 no # Type # perl -Mre=debug broken.pl # where broken.pl is the program with the qr//o in it, to # see exactly why it fails. # # .keywords # Perl # Perl qr # Perl qr//o # .ekeywords # use feature qw(say); @re = qw(^a$ ^b$); @re = map { qr /$_/ } @re; @line = qw(a b c); foreach $line (@line) { say $line; # In Perl 5.10 here's one way to print "yes" or "no" # depending if a string matches any qr'ed regular expressions. $t = 0; foreach (@re) { ($line =~ $_) and $t = 1, last; } say ' 1 ' . ($t ? 'yes' : 'no'); # Get same results in Perl 5.12: say ' 2 ' . ($line ~~ @re ? 'yes' : 'no'); }