From mark at purdue.edu Wed May 4 08:56:59 2011 From: mark at purdue.edu (Mark Senn) Date: Wed, 04 May 2011 11:56:59 -0400 Subject: [Purdue-pm] Perl 6 regexes are different Message-ID: <8446.1304524619@pier.ecn.purdue.edu> While debugging a chunk of code in Perl 6 (P6), I forgot about how P6 regexes work differently than in Perl 5 (P5) and suspected the problem wasn't with regexes anyway. I was wrong. P6 automatically ignores spaces in regexes. So in P6 the regex /two words/ is equivalent to /twowords/ in P6 or /two words/x in P5. To make spaces significant in P6 regexes do, for example, m:sigspace/two words/ or, m:s/two words/ for short. The "m" is short for "match". The "s" is short for "sigspace"---sigspace means spaces in the regex are significant. Just another one of the things our fingers know how to do in P5 that we'll need to engage our brains to do in P6. Touch your right index finger against the top of your head, your left index finger against the top of your foot, and say "regex"---it will help you remember this message. -mark From jacoby at purdue.edu Mon May 16 07:32:19 2011 From: jacoby at purdue.edu (Dave Jacoby) Date: Mon, 16 May 2011 10:32:19 -0400 Subject: [Purdue-pm] Regex Unification Message-ID: <4DD13573.7020207@purdue.edu> I have this bank of regexes in my code. $requests2{ $request }->{ $href->{ accession_id } } ->{ library } =~ s/\W/\-/g ; $requests2{ $request }->{ $href->{ accession_id } } ->{ library } =~ s/_/\-/g ; $requests2{ $request }->{ $href->{ accession_id } } ->{ library } =~ s/-+/-/g ; $requests2{ $request }->{ $href->{ accession_id } } ->{ library } =~ s/-$//g ; I'm thinking that I can simplify this a lot. Change the \W and _ regexes to \W+ and _+ and you reduce the need for the s/-+/-/, so we can reduce it, I think, to $requests2{ $request }->{ $href->{ accession_id } } ->{ library } =~ s/[\W_-]+/\-/g ; I'd have to bash that regex before I'm comfortable putting it into production. But the last part, getting rid of dashes at the end of a string, can I roll that into the bigger regex? I'm not seeing how right now. -- Dave Jacoby Address: WSLR S049 Code Maker Mail: jacoby at purdue.edu Purdue University Phone: 765.49.67368 1057 days until the end of XP support From mark at ecn.purdue.edu Mon May 16 08:31:05 2011 From: mark at ecn.purdue.edu (Mark Senn) Date: Mon, 16 May 2011 11:31:05 -0400 Subject: [Purdue-pm] Regex Unification In-Reply-To: <4DD13573.7020207@purdue.edu> References: <4DD13573.7020207@purdue.edu> Message-ID: <14606.1305559865@pier.ecn.purdue.edu> > I have this bank of regexes in my code. > > $requests2{ $request }->{ $href->{ accession_id } } > ->{ library } =~ s/\W/\-/g ; > $requests2{ $request }->{ $href->{ accession_id } } > ->{ library } =~ s/_/\-/g ; > $requests2{ $request }->{ $href->{ accession_id } } > ->{ library } =~ s/-+/-/g ; > $requests2{ $request }->{ $href->{ accession_id } } > ->{ library } =~ s/-$//g ; > > I'm thinking that I can simplify this a lot. > > Change the \W and _ regexes to \W+ and _+ and you reduce the need for > the s/-+/-/, so we can reduce it, I think, to > > $requests2{ $request }->{ $href->{ accession_id } } > ->{ library } =~ s/[\W_-]+/\-/g ; > > I'd have to bash that regex before I'm comfortable putting it into > production. > > But the last part, getting rid of dashes at the end of a string, can I > roll that into the bigger regex? I'm not seeing how right now. I prefer the second of the three solutions below. #!/usr/local/bin/perl $s = '!@#$%^&*(){}--__--}{)(*&^%$#@!abc--'; $_ = $S . "\n" . $s . "\n"; s/\W/\-/g; s/_/\-/g; s/-+/-/g; s/-$//g; print "$_\n"; $s = '!@#$%^&*(){}--__--}{)(*&^%$#@!abc--'; $_ = $S . "\n" . $s . "\n"; s/[\W_]/-/g; # Change nonword or '_' characters to '-' everywhere. # This will change any newlines to '-'. s/-+/-/g; # Change two or more consecutive '-' characters # to one '-' everywhere. s/-$//; # Delete any '-' at the end of the string. print "$_\n"; $s = '!@#$%^&*(){}--__--}{)(*&^%$#@!abc--'; $_ = $S . "\n" . $s . "\n"; s/[\W_-]+/-/g; # Change consecutive nonword, '_', or '-' characters # to '-' everywhere. # This will change any newlines to '-'. s/-$//; # Delete any '-' at the end of the string. print "$_\n"; -mark From bradley.d.andersen at gmail.com Mon May 16 10:31:28 2011 From: bradley.d.andersen at gmail.com (Bradley Andersen) Date: Mon, 16 May 2011 13:31:28 -0400 Subject: [Purdue-pm] Regex Unification In-Reply-To: <14606.1305559865@pier.ecn.purdue.edu> References: <4DD13573.7020207@purdue.edu> <14606.1305559865@pier.ecn.purdue.edu> Message-ID: Really?! Ugh. I will acknowledge readily that I have to squint very hard to understand your regexs, Mark, but, I have called out Larry Wall for writing less terse stuff than this :) On Mon, May 16, 2011 at 11:31 AM, Mark Senn wrote: > > I have this bank of regexes in my code. > > > > $requests2{ $request }->{ $href->{ accession_id } } > > ->{ library } =~ s/\W/\-/g ; > > $requests2{ $request }->{ $href->{ accession_id } } > > ->{ library } =~ s/_/\-/g ; > > $requests2{ $request }->{ $href->{ accession_id } } > > ->{ library } =~ s/-+/-/g ; > > $requests2{ $request }->{ $href->{ accession_id } } > > ->{ library } =~ s/-$//g ; > > > > I'm thinking that I can simplify this a lot. > > > > Change the \W and _ regexes to \W+ and _+ and you reduce the need for > > the s/-+/-/, so we can reduce it, I think, to > > > > $requests2{ $request }->{ $href->{ accession_id } } > > ->{ library } =~ s/[\W_-]+/\-/g ; > > > > I'd have to bash that regex before I'm comfortable putting it into > > production. > > > > But the last part, getting rid of dashes at the end of a string, can I > > roll that into the bigger regex? I'm not seeing how right now. > > I prefer the second of the three solutions below. > > #!/usr/local/bin/perl > > $s = '!@#$%^&*(){}--__--}{)(*&^%$#@!abc--'; > $_ = $S . "\n" . $s . "\n"; > s/\W/\-/g; > s/_/\-/g; > s/-+/-/g; > s/-$//g; > print "$_\n"; > > $s = '!@#$%^&*(){}--__--}{)(*&^%$#@!abc--'; > $_ = $S . "\n" . $s . "\n"; > s/[\W_]/-/g; # Change nonword or '_' characters to '-' everywhere. > # This will change any newlines to '-'. > s/-+/-/g; # Change two or more consecutive '-' characters > # to one '-' everywhere. > s/-$//; # Delete any '-' at the end of the string. > print "$_\n"; > > $s = '!@#$%^&*(){}--__--}{)(*&^%$#@!abc--'; > $_ = $S . "\n" . $s . "\n"; > s/[\W_-]+/-/g; # Change consecutive nonword, '_', or '-' characters > # to '-' everywhere. > # This will change any newlines to '-'. > s/-$//; # Delete any '-' at the end of the string. > print "$_\n"; > > -mark > _______________________________________________ > Purdue-pm mailing list > Purdue-pm at pm.org > http://mail.pm.org/mailman/listinfo/purdue-pm > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jacoby at purdue.edu Tue May 17 06:02:01 2011 From: jacoby at purdue.edu (Dave Jacoby) Date: Tue, 17 May 2011 09:02:01 -0400 Subject: [Purdue-pm] Meeting Today Message-ID: <4DD271C9.5030809@purdue.edu> This is just a reminder that we'll be be having our regular monthly Perl Mongers meeting today. * Mark will be talking about Perl 6, home automation and TEZ. * Joe might be comparing plotting with Perl and with Python, or might not, and might be reviewing Modern Perl, or might not. * And I will be showing off Sikuli, a tool written in Java which uses the Java Python implementation, Jython, as the scripting engine. Plus the pre-meeting conversation we all know and love. Come Monger Perl at the same camel-time (11:30-1:30) and same camel-station (WSLR 116). -- Dave Jacoby Address: WSLR S049 Code Maker Mail: jacoby at purdue.edu Purdue University Phone: 765.49.67368 1056 days until the end of XP support From mark at purdue.edu Thu May 19 04:42:00 2011 From: mark at purdue.edu (Mark Senn) Date: Thu, 19 May 2011 07:42:00 -0400 Subject: [Purdue-pm] new Rakudo Perl 6 compiler Message-ID: <1950.1305805320@pier.ecn.purdue.edu> A new Rakudo Perl 6 compiler is available. See below. -mark >Date: Thu, 19 May 2011 03:51:47 -0400 >Subject: Announce: Rakudo Perl 6 compiler development release #41 ("Dahut") >From: JD Horelick >To: perl6-compiler at perl.org >X-ECN-MailServer-VirusScanned: by amavisd-new >X-ECN-MailServer-Origination: x6.develooper.com [207.171.7.86] >X-ECN-MailServer-SpamScanAdvice: DoScan > >On behalf of the Rakudo development team, I'm happy to announce the >May 2011 release of Rakudo Perl #41 "Dahut". Rakudo is an >implementation of Perl 6 on the Parrot Virtual Machine (see >). The tarball for the May 2011 release >is available from . > >Please note: This announcement is not for the Rakudo Star distribution -- >it's announcing a new release of the compiler only. For the latest >Rakudo Star release, see . > >The Rakudo Perl compiler follows a monthly release cycle, with each release >named after a Perl Mongers group. The May 2011 release is code named >"Dahut". > >Some of the specific changes and improvements occurring with this >release include: > >* added a call counter for builtins in Perl 6-level subroutines >* gcd (greatest common divisor) and lcm (largest common multiple) operators >* implemented Int.base > >For a more detailed list of changes, see "docs/ChangeLog". > >The development team thanks all of our contributors and sponsors for >making Rakudo Perl possible, as well as those people who worked on >Parrot, the Perl 6 test suite and the specification. > >The following people contributed to this release: > >Patrick R. Michaud, Moritz Lenz, Jonathan Scott Duff, Tadeusz So?nierz, >Carl Masak, Solomon Foster, bacek > >If you would like to contribute, see , ask on >the perl6-compiler at perl.org mailing list, or ask on IRC #perl6 on freenode. > >The next release of Rakudo (#42) is scheduled for June 23, 2011. >A list of the other planned release dates and code names for 2011 is >available in the "docs/release_guide.pod" file. In general, Rakudo >development releases are scheduled to occur two days after each >Parrot monthly release. Parrot releases the third Tuesday of each month. > >Have fun! From jacoby at purdue.edu Tue May 24 13:20:30 2011 From: jacoby at purdue.edu (Dave Jacoby) Date: Tue, 24 May 2011 16:20:30 -0400 Subject: [Purdue-pm] Code Question Message-ID: <4DDC130E.10005@purdue.edu> -----8<-- The Code ------------------------------------------------ #!/usr/bin/perl use strict ; use warnings ; my $index = 9 ; for ( 1 .. 5 ) { foo() ; } print qq{OUTSIDE: $index \n}; { my $index = 0 ; sub foo { print qq{INDEX: $index \n} ; $index++ ; } } -----8<-- Expected Outcome ---------------------------------------- INDEX: 0 INDEX: 1 INDEX: 2 INDEX: 3 INDEX: 4 OUTSIDE: 9 -----8<-- Real Outcome -------------------------------------------- Use of uninitialized value $index in concatenation (.) or string at /home/jacoby/sub_test.pl line 12. INDEX: INDEX: 1 INDEX: 2 INDEX: 3 INDEX: 4 OUTSIDE: 9 -----8<-- Question ------------------------------------------------ If I comment out "$index = 0 ;", it uses the $index in the global scope. I've seen this trick before. Make a block, put a variable and a subroutine in the block. The subroutine is the only place you can see the variable, but the variable exists outside of the subroutine, giving it more permanence. I got it to work like I want by using a BEGIN{} block but I don't recall having to do that before. What magic bit of syntax am I missing? Or have I blocked the trauma of having to use a BEGIN block? -- Dave Jacoby Address: WSLR S049 Code Maker Mail: jacoby at purdue.edu Purdue University Phone: 765.49.67368 1049 days until the end of XP support From westerman at purdue.edu Tue May 24 13:33:52 2011 From: westerman at purdue.edu (Rick Westerman) Date: Tue, 24 May 2011 16:33:52 -0400 (EDT) Subject: [Purdue-pm] Code Question In-Reply-To: <4DDC130E.10005@purdue.edu> Message-ID: <196561666.28360.1306269232046.JavaMail.root@mailhub016.itcs.purdue.edu> You have a correct idea but variable and the subroutine need to be declared early before the routine is called. Or within, as you point out, with a BEGIN statement. ----- Original Message ----- > -----8<-- The Code ------------------------------------------------ > #!/usr/bin/perl > use strict ; > use warnings ; > > my $index = 9 ; > for ( 1 .. 5 ) { foo() ; } > print qq{OUTSIDE: $index \n}; > I.e., either put this at the top of your script ... or ... put a BEGIN in front of it. > { > my $index = 0 ; > sub foo { > print qq{INDEX: $index \n} ; > $index++ ; > } > } > > -----8<-- Expected Outcome ---------------------------------------- > INDEX: 0 > INDEX: 1 > INDEX: 2 > INDEX: 3 > INDEX: 4 > OUTSIDE: 9 > > -----8<-- Real Outcome -------------------------------------------- > Use of uninitialized value $index in concatenation (.) or string at > /home/jacoby/sub_test.pl line 12. > INDEX: > INDEX: 1 > INDEX: 2 > INDEX: 3 > INDEX: 4 > OUTSIDE: 9 > > -----8<-- Question ------------------------------------------------ > > If I comment out "$index = 0 ;", it uses the $index in the global > scope. > > I've seen this trick before. Make a block, put a variable and a > subroutine in the block. The subroutine is the only place you can see > the variable, but the variable exists outside of the subroutine, > giving > it more permanence. I got it to work like I want by using a BEGIN{} > block but I don't recall having to do that before. > > What magic bit of syntax am I missing? Or have I blocked the trauma of > having to use a BEGIN block? > > -- > Dave Jacoby Address: WSLR S049 > Code Maker Mail: jacoby at purdue.edu > Purdue University Phone: 765.49.67368 > 1049 days until the end of XP support > > _______________________________________________ > Purdue-pm mailing list > Purdue-pm at pm.org > http://mail.pm.org/mailman/listinfo/purdue-pm -- 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 Wed May 25 06:38:36 2011 From: gizmo at purdue.edu (Joe Kline) Date: Wed, 25 May 2011 09:38:36 -0400 Subject: [Purdue-pm] Code Question In-Reply-To: <196561666.28360.1306269232046.JavaMail.root@mailhub016.itcs.purdue.edu> References: <196561666.28360.1306269232046.JavaMail.root@mailhub016.itcs.purdue.edu> Message-ID: <4DDD065C.8020301@purdue.edu> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 You might also try the state or our declarations. Their scope is a bit more interesting than the standard my and local. I think our might be in 5.8.something and state didn't get in until 5.10 joe -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.5 (GNU/Linux) Comment: Using GnuPG with Red Hat - http://enigmail.mozdev.org/ iD8DBQFN3QZbb0mzA2gRTpkRAjLHAKCJwcgjWgsPOwX8+MLWY64FB7PADACePJvt RM2BW8srrlJo8D6/p1I2Ot4= =LqOy -----END PGP SIGNATURE----- From jacoby at purdue.edu Wed May 25 07:55:53 2011 From: jacoby at purdue.edu (Dave Jacoby) Date: Wed, 25 May 2011 10:55:53 -0400 Subject: [Purdue-pm] Code Question In-Reply-To: <4DDD065C.8020301@purdue.edu> References: <196561666.28360.1306269232046.JavaMail.root@mailhub016.itcs.purdue.edu> <4DDD065C.8020301@purdue.edu> Message-ID: <4DDD1879.9060502@purdue.edu> On 5/25/2011 9:38 AM, Joe Kline wrote: > You might also try the state or our declarations. > > Their scope is a bit more interesting than the standard my and local. > > I think our might be in 5.8.something and state didn't get in until 5.10 > Unfortunately, this is running on RCAC machines, which run RHEL and thus Perl 5.8.8. But I'll look up state and our. -- Dave Jacoby Address: WSLR S049 Code Maker Mail: jacoby at purdue.edu Purdue University Phone: 765.49.67368 1048 days until the end of XP support From gizmo at purdue.edu Fri May 27 12:25:10 2011 From: gizmo at purdue.edu (Joe Kline) Date: Fri, 27 May 2011 15:25:10 -0400 Subject: [Purdue-pm] Perl6 in real life Message-ID: <4DDFFA96.8090701@purdue.edu> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 A perl blog post that I mentioned to Mark. http://blogs.perl.org/users/jlloyd/2011/05/perl6----irl-in-real-life.html joe -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.5 (GNU/Linux) Comment: Using GnuPG with Red Hat - http://enigmail.mozdev.org/ iD8DBQFN3/qVb0mzA2gRTpkRAm5NAJ9HeQ9lYPdpaOdjtgPtikyX3R7e6wCeLuEc FREsg8KFKwp/3AXWFfkKSo8= =A3A2 -----END PGP SIGNATURE-----