From rkleeman at energoncube.net Fri Mar 12 13:19:57 2010 From: rkleeman at energoncube.net (Bob Kleemann) Date: Fri, 12 Mar 2010 13:19:57 -0800 Subject: [San-Diego-pm] Fwd: March Mingle Networking Invitation to SD Perl Mongers In-Reply-To: <027301cac221$bd03c290$370b47b0$@org> References: <027301cac221$bd03c290$370b47b0$@org> Message-ID: I have enjoyed this event in the past. Please contact Phelan directly if you plan to go this year. ---------- Forwarded message ---------- From: Phelan from SD Tech Scene Date: Fri, Mar 12, 2010 at 12:22 PM Subject: March Mingle Networking Invitation to SD Perl Mongers Hi Bob, It's time to open up your calendar and get set for March's biggest tech mixer! March Mingle will be held on the evening of Tuesday, March 30th, 2010 from 6:30 to 9:00 at San Diego?s newest and hottest Italian restaurant in North Park, Il Postino. If you don't remember, or haven't been to one yet, March Mingle is a night in which San Diego's tech community gets together for a mixer of epic proportions that?s all about socializing and enjoying a fun atmosphere with good food, drinks, and people. There won't be any presentations, demos, or pitches of any kind -- this event is for trading war stories, swapping tips and tricks, and just having a great time. This event is technologically agnostic; whether you develop for the iPhone or write login pages like a code monkey, we'd love to see you there! And special thanks to HP Touch Printing ?for sponsoring, we are able to offer our sixth annual March Mingle for free! If you would like to have your user group attend, please reply back to this email so we can get an idea of which groups will be represented. The venue is limited to 300. We wouldn't want you to miss this awesome event so make sure to RSVP if you plan on attending. Please help spread the word by posting to your user groups forum / website or send an email blast to your group list with this invitation. Looking forward to seeing you there. The March Mingle Organizers Phelan, Enrique, Patrick, June, Jen and Jarin http://SDTechScene.org | http://marchmingle.com One city. One tech scene. One calendar. From rkleeman at energoncube.net Tue Mar 16 13:37:02 2010 From: rkleeman at energoncube.net (Bob Kleemann) Date: Tue, 16 Mar 2010 13:37:02 -0700 Subject: [San-Diego-pm] Meeting This Week and More Message-ID: Hello Perl Mongers, We have our normal monthly meeting this week, on Thursday, March 18th at 7 PM at the Anonymizer offices near Mira Mesa Blvd and I-805. In addition to our normal topics, we'll discuss: * Chris has promised a presentation on the subject he has been dealing with a lot, XS. It should be a good intro to an aspect of Perl not often seen, heard, or talked about much. * Damian Conway is coming. The date (either Wednesday, April 7 or Thursday, April 8), time, and location are still to be determined. If you have preferences of dates or topics (http://damian.conway.org/Seminars/), please let us know or come along and discuss. As always, please drop me a line (if you can) to let me know that you're coming. I look forward to seeing you all soon. From rkleeman at energoncube.net Thu Mar 18 14:54:14 2010 From: rkleeman at energoncube.net (Bob Kleemann) Date: Thu, 18 Mar 2010 14:54:14 -0700 Subject: [San-Diego-pm] Meeting Tonight and Damian Conway Message-ID: Perl Mongers, Just a reminder, we're having our normal monthly meeting tonight at 7 PM at the Anonymizer.com offices near Mira Mesa Blvd and I-805. Bring your thoughts, questions, ideas, and what-not and we'll discuss them. We're also going to be treated to a small education of XS by Chris. We also plan to talk about Damian's upcoming visit, so take a look at the list of his seminars (http://damian.conway.org/Seminars/) and we'll discuss what sounds most interesting. I look forward to seeing you all tonight! From ruberad at gmail.com Fri Mar 19 22:14:13 2010 From: ruberad at gmail.com (Reuben Settergren) Date: Fri, 19 Mar 2010 22:14:13 -0700 Subject: [San-Diego-pm] Recompiling global substitution RE? In-Reply-To: <89038bc01003191535i14d674b0xeabfd4c0940ec5d4@mail.gmail.com> References: <89038bc01003191535i14d674b0xeabfd4c0940ec5d4@mail.gmail.com> Message-ID: <89038bc01003192214n4b621e11w11bdda1a6d8daf55@mail.gmail.com> Hi all, I've got a Perl problem that's got me stumped. Any help would be appreciated. Consider the following small perl program, which exemplifies a problem I am having with a script generates HTML sw verification reports, and is supposed to colorize numbers according to how they verified against what the numbers are supposed to be. To make things simpler, ?1? is abbreviated as ?sg1s?: #! /bin/perl $s = "1 2 3 1 2 3 1 2 3"; # what I have $t = "sg1s 2 3 sr1s 2 3 1 sy2s 3"; # what I want @nums = qw(1 1 2); @cols = qw(g r y); $i=$j=0; $s =~ s!($nums[$i++])!s$cols[$j++]$1s!g; print "Want: '$t'\n"; print "Got: '$s'\n"; print "i is now $i\n"; print "j is now $j\n"; The output of this program is unfortunately: Want: 'sg1s 2 3 sr1s 2 3 1 sy2s 3' Got: 'sg1s 2 3 sr1s 2 3 sy1s 2 3' i is now 1 j is now 3 Perl ended up incorrectly coloring the third ?1? yellow, instead of the third ?2?, because in the substitution regular expression, the left (matching) side was evaluated/compiled only once, while the right (replacement) side was evaluated/interpolated three times (as desired). I know that there are ways to force the left side of the RE to compile only once (/o modifier, qr// operator), and there are ways to force eval in the right side (/e and /ee modifiers ? although in this case, standard interpolation was sufficient), but is there any way I can force the *left* side to compile *multiple* times? (Even within the same /g substitution?) I tried a few constructs using the \G (start matching from previous position) zero-width assertion, but only managed to get myself into infinite loops. I'd appreciate any help anyone can offer -- including "What an idiot, the RIGHT way to do that is completely different! (And here it is...)" thx for thinking for me! r -------------- next part -------------- An HTML attachment was scrubbed... URL: From gautam.dey77 at gmail.com Sat Mar 20 08:41:38 2010 From: gautam.dey77 at gmail.com (Gautam Dey) Date: Sat, 20 Mar 2010 08:41:38 -0700 Subject: [San-Diego-pm] Recompiling global substitution RE? In-Reply-To: <89038bc01003192214n4b621e11w11bdda1a6d8daf55@mail.gmail.com> References: <89038bc01003191535i14d674b0xeabfd4c0940ec5d4@mail.gmail.com> <89038bc01003192214n4b621e11w11bdda1a6d8daf55@mail.gmail.com> Message-ID: <9f662fe01003200841k14a3c737p1ef648d92a6bd52b@mail.gmail.com> Reuben, Trying to figure out how you are determining when to do the substitution? 2010/3/19 Reuben Settergren : > > #! /bin/perl > $s = "1 2 3 1 2 3 1 2 3"; ? ? ? ? ?# what I have > $t = "sg1s 2 3 sr1s 2 3 1 sy2s 3"; # what I want How do you know that there are two elements after the first 1 to generate the "sg1s 2 3" and that there are three elements after the 1 to generate the "sr1s 2 3 1" and that there is only 1 element after the 2 to generate the "sy2s 3". The transformation seem a bit more complicated then what can be done with a simple regular expresion . s/something/text/g replaces all occurrences of something with text. So, you regular expression seems to be replacing all occurrences of 1 with the appropriate evaluated code. But, I'm not sure as 's!($nums[$i++])!s$cols[$j++]$1s!g' is a bit on the unusual side of things. Gautam. > @nums = qw(1 1 2); > @cols = qw(g r y); > $i=$j=0; > $s =~ s!($nums[$i++])!s$cols[$j++]$1s!g; > print "Want: '$t'\n"; > print "Got: ?'$s'\n"; > print "i is now $i\n"; > print "j is now $j\n"; > > The output of this program is unfortunately: > > Want: 'sg1s 2 3 sr1s 2 3 1 sy2s 3' > Got: ?'sg1s 2 3 sr1s 2 3 sy1s 2 3' > i is now 1 > j is now 3 > > Perl ended up incorrectly coloring the third ?1? yellow, instead of the > third ?2?, because in the substitution regular expression, the left > (matching) side was evaluated/compiled only once, while the right > (replacement) side was evaluated/interpolated three times (as desired). > > I know that there are ways to force the left side of the RE to compile only > once (/o modifier, qr// operator), and there are ways to force eval in the > right side (/e and /ee modifiers ? although in this case, standard > interpolation was sufficient), but is there any way I can force > the?left?side to compile?multiple?times? (Even within the same /g > substitution?) I tried a few constructs using the \G (start matching from > previous position) zero-width assertion, but only managed to get myself into > infinite loops. > > I'd appreciate any help anyone can offer -- including "What an idiot, the > RIGHT way to do that is completely different! (And here it is...)" > > thx for thinking for me! > > r > > > > _______________________________________________ > San-Diego-pm mailing list > San-Diego-pm at pm.org > http://mail.pm.org/mailman/listinfo/san-diego-pm > From contact at pattimccreary.com Sat Mar 20 10:40:11 2010 From: contact at pattimccreary.com (Patti McCreary) Date: Sat, 20 Mar 2010 10:40:11 -0700 (PDT) Subject: [San-Diego-pm] eCommerce Dev job in Carlsbad Message-ID: <33405.75.80.166.117.1269106811.squirrel@mail.mebust.com> Hey all, The company I contract for (Zoovy, Inc) is looking for an additional eCommerce Developer (full-time onsite employee). We program almost exclusively in Perl but would be willing to train an accomplished PHP, Ruby or Python developer. The full listing is on Jobing.com http://sandiego.jobing.com/Job_Details2.asp?JobID=2238544&SearchID=229601797&Position=0&CameFrom=Job Let me know if you are interested or have any questions. Thanks, Patti McCreary Senior Developer Zoovy, Inc -- Patti McCreary contact at pattimccreary.com 858-245-7374 From ruberad at gmail.com Sat Mar 20 16:13:23 2010 From: ruberad at gmail.com (Reuben Settergren) Date: Sat, 20 Mar 2010 16:13:23 -0700 Subject: [San-Diego-pm] Recompiling global substitution RE? In-Reply-To: <9f662fe01003200841k14a3c737p1ef648d92a6bd52b@mail.gmail.com> References: <89038bc01003191535i14d674b0xeabfd4c0940ec5d4@mail.gmail.com> <89038bc01003192214n4b621e11w11bdda1a6d8daf55@mail.gmail.com> <9f662fe01003200841k14a3c737p1ef648d92a6bd52b@mail.gmail.com> Message-ID: <89038bc01003201613k6607af23y67f04c68c22e03a6@mail.gmail.com> Hey gang, I think I have a solution now, with the help of Mark Johnson. I should give you more clarification that my actual problem (still simplified) looks more like: DIST - Distance DISTANCE: 12.3456 ft 4.5678 m STD DEV: 3.4567 ft 1.2345 m AREA - Area AREA: 2345.6789 ft^2 345.6789 m^2 PERIMETER: 234.5678 ft 89.0123 m STD DEV: 3.4567 ft 1.2345 m DIST - Distance DISTANCE: 12.3456 ft 4.5678 m STD DEV: 3.4567 ft 1.2345 m DIST - Distance DISTANCE: 8.9012 ft 3.0123 m STD DEV: 1.2345 ft 0.4567 m ...etc So in any one situation, I will have a set of numbers/colors for a particular combination of function/metric/unit (i.e. DIST/'STD DEV'/ft: (3.4567,3.4567,1.2345),(red,green,yellow)). So I have to avoid the other functions (e.g. AREA) that might have the same numbers. Note my first attempt for $i (0..$#nums) { $str =~ s{($function.*$metric.*)(?)($vals[$i]\s+$unit)} {$1$2} } didn't work because in the second time through the loop, $1 matched from the very beginning, and $2 was the 3.4567 in the AREA function. But with Mark Johnson's idea, I can chomp through my whole file-in-one-string bit-by-bit, something like: $head = ''; $tail = $s; for my $i ( 0 .. $#nums ) { $tail =~ s/(.*?$function.*?$metric.*?)($nums[$i]\s+$unit)(.*)/$3/; $head .= "$1$2"; } $s = "$head$tail"; If there isn't already a name for this cool kind of trick, there should be: train cars? chewandswallow? sausage grinder? Any other ideas? r On Sat, Mar 20, 2010 at 8:41 AM, Gautam Dey wrote: > Reuben, > > Trying to figure out how you are determining when to do the substitution? > > > > 2010/3/19 Reuben Settergren : > > > > > #! /bin/perl > > $s = "1 2 3 1 2 3 1 2 3"; # what I have > > $t = "sg1s 2 3 sr1s 2 3 1 sy2s 3"; # what I want > > How do you know that there are two elements after the first 1 to generate > the "sg1s 2 3" and that there are three elements after the 1 to generate > the > "sr1s 2 3 1" and that there is only 1 element after the 2 to generate the > "sy2s 3". The transformation seem a bit more complicated then what can > be done with a simple regular expresion . > > s/something/text/g replaces all occurrences of something with text. > So, you regular expression seems to be replacing all occurrences of 1 > with the appropriate evaluated code. But, I'm not sure as > 's!($nums[$i++])!s$cols[$j++]$1s!g' is a bit on the unusual side of > things. > > Gautam. > > > @nums = qw(1 1 2); > > @cols = qw(g r y); > > $i=$j=0; > > $s =~ s!($nums[$i++])!s$cols[$j++]$1s!g; > > print "Want: '$t'\n"; > > print "Got: '$s'\n"; > > print "i is now $i\n"; > > print "j is now $j\n"; > > > > The output of this program is unfortunately: > > > > Want: 'sg1s 2 3 sr1s 2 3 1 sy2s 3' > > Got: 'sg1s 2 3 sr1s 2 3 sy1s 2 3' > > i is now 1 > > j is now 3 > > > > Perl ended up incorrectly coloring the third ?1? yellow, instead of the > > third ?2?, because in the substitution regular expression, the left > > (matching) side was evaluated/compiled only once, while the right > > (replacement) side was evaluated/interpolated three times (as desired). > > > > I know that there are ways to force the left side of the RE to compile > only > > once (/o modifier, qr// operator), and there are ways to force eval in > the > > right side (/e and /ee modifiers ? although in this case, standard > > interpolation was sufficient), but is there any way I can force > > the left side to compile multiple times? (Even within the same /g > > substitution?) I tried a few constructs using the \G (start matching from > > previous position) zero-width assertion, but only managed to get myself > into > > infinite loops. > > > > I'd appreciate any help anyone can offer -- including "What an idiot, the > > RIGHT way to do that is completely different! (And here it is...)" > > > > thx for thinking for me! > > > > r > > > > > > > > _______________________________________________ > > San-Diego-pm mailing list > > San-Diego-pm at pm.org > > http://mail.pm.org/mailman/listinfo/san-diego-pm > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From tkil at scrye.com Sat Mar 20 22:36:47 2010 From: tkil at scrye.com (Anthony Foiani) Date: Sat, 20 Mar 2010 23:36:47 -0600 Subject: [San-Diego-pm] selective matching (was: Re: Recompiling global substitution RE?) In-Reply-To: <89038bc01003201613k6607af23y67f04c68c22e03a6@mail.gmail.com> (Reuben Settergren's message of "Sat, 20 Mar 2010 16:13:23 -0700") References: <89038bc01003191535i14d674b0xeabfd4c0940ec5d4@mail.gmail.com> <89038bc01003192214n4b621e11w11bdda1a6d8daf55@mail.gmail.com> <9f662fe01003200841k14a3c737p1ef648d92a6bd52b@mail.gmail.com> <89038bc01003201613k6607af23y67f04c68c22e03a6@mail.gmail.com> Message-ID: Reuben Settergren writes: > > I should give you more clarification that my actual problem > (still simplified) looks more like: > > DIST - Distance > DISTANCE: 12.3456 ft 4.5678 m > STD DEV: 3.4567 ft 1.2345 m > > AREA - Area > AREA: 2345.6789 ft^2 345.6789 m^2 > PERIMETER: 234.5678 ft 89.0123 m > STD DEV: 3.4567 ft 1.2345 m > > DIST - Distance > DISTANCE: 12.3456 ft 4.5678 m > STD DEV: 3.4567 ft 1.2345 m > > DIST - Distance > DISTANCE: 8.9012 ft 3.0123 m > STD DEV: 1.2345 ft 0.4567 m > > ...etc To be honest, neither the original problem description, nor this clarification, made much sense to me. I suspect that others on the list had similar problems. What are you actually checking against what? Where are you getting your "good" values? Where are you getting "columns", and their colors? > So in any one situation, I will have a set of numbers/colors for a > particular combination of function/metric/unit (i.e. DIST/'STD DEV'/ft: > (3.4567,3.4567,1.2345),(red,green,yellow)). So I have to avoid the > other functions (e.g. AREA) that might have the same numbers. Ok, this makes a bit more sense. See below for my opinion of a good way to tackle this problem. > But with Mark Johnson's idea, I can chomp through my whole > file-in-one-string bit-by-bit, something like: > > $head = ''; > $tail = $s; > for my $i ( 0 .. $#nums ) { > $tail =~ > s/(.*?$function.*?$metric.*?)($nums[$i]\s+$unit)(.*)/$3/; > $head .= "$1$2"; > } > $s = "$head$tail"; > > If there isn't already a name for this cool kind of trick, there should > be: train cars? chewandswallow? sausage grinder? Any other ideas? It's a very common pattern in functional and declarative languages (lisp and prolog, if you want representative examples). In Lisp, the pattern is to grab however many args off the front of the list, and use the "&rest" specifier to put the remaining args into a named list. Then you do whatever you need to do with the head args, and call yourself on the remainder: | (defun process (head1 head2 head3 &rest tail) | (cond ((nilp tail) "") | (t (cons (munge head1 head2 head3) | (process tail))))) Prolog would do that somewhat like: | process( [], [] ). | process( [ Head1, Head2, Head3 | Tail ], [ MungedHead | MungedTail ] ) :- | munge( Head1, Head2, Head3, MungedHead ), | process( Tail, MungedTail ). (I'm quite rusty on both languages, but hopefully you get the idea.) Both of these languages (and this style of programming) go back at least into the 70s; Lisp probably goes back into the 60s. Or you could use Mathematica, which combines the two... My first approach was to use text matching to build domain-level entities, and then operate on those entities. You don't have to go full-bore OOP, but that's basically the end point of following this line of thinking. In this case, I'll just build up a hash for each "function", probably with some nested hashes for each metric within the function. Then you can match those iteratively against your criteria. (And yes, I really would write comments like this.) You can see the result here: http://scrye.com/~tkil/perl/reuben1.plx I didn't care for how that forced the highlighting functions to know the output format, though; about halfway through that implementation (although I did finish it), I realised the the "hard part" was encoding the criteria. Both of my programs use this structure: | my @CRITERIA = | ( | | { function => 'DIST', | metric => 'STD DEV', | units => 'ft', | ranges => [ 3.4567, # center value | '' => 0.001, # center tolerance | green => 0.01, # color => tolerance | yellow => 0.2, | red => -1 ] }, # default | | { function => 'AREA', | metric => 'STD DEV', | units => 'ft^2', | ranges => [ 2.78, | '' => 0.01, | blue => 0.1, | orange => 0.3, | red => -1 ] }, | | { function => 'DIST2', | metric => 'DISTANCE', | units => 'm', | ranges => [ 3.2, | '' => 0.01, | green => 0.1, | orange => 0.3, | red => -1 ] }, | | # if multiple criteria matches the same measurement, the | # later criteria will be nested inside the earlier ones. | { function => 'DIST2', | metric => 'DISTANCE', | units => 'm', | ranges => [ 3.2, | '' => 0.01, | green2 => 0.1, | orange2 => 0.3, | red2 => -1 ] } | | ); # end of @CRITERIA (Although only my second effort handles the stacked-rules case described in the last criterion.) The second one works on the individual lines as they come in, using the latest function name as a primitive state variable. The main loop there: | my @cur_crit; | | while ( my $line = ) | { | if ( $line =~ $func_start_re ) | { | my $func = $1; | @cur_crit = grep { $_->{function} eq $func } @CRITERIA; | } | elsif ( $line =~ $blank_line_re ) | { | undef @cur_crit; | } | elsif ( $line =~ $metric_line_re ) | { | my ( $indent, $metric, $space, $vals ) = | ( $1, $2, $3, $4 ); | | foreach my $crit ( grep { $_->{metric} eq $metric } @cur_crit ) | { | $vals = highlight $vals, $crit; | } | | $line = join '', $indent, $metric, $space, $vals; | } | print $line; | } The whole program can be found at: http://scrye.com/~tkil/perl/reuben2.plx That's the one that I think is the better code, depending on how closely your sample data and criteria match your real-world problem. With this input data: | DIST - Distance | DISTANCE: 12.3456 ft 4.5678 m | STD DEV: 3.4567 ft 1.2345 m | | AREA - Area | AREA: 2345.6789 ft^2 345.6789 m^2 | PERIMETER: 234.5678 ft 89.0123 m | STD DEV: 3.4567 ft 1.2345 m | | DIST - Distance | DISTANCE: 12.3456 ft 4.5678 m | STD DEV: 3.4567 ft 1.2345 m | | DIST - Distance | DISTANCE: 8.9012 ft 3.0123 m | STD DEV: 1.2345 ft 0.4567 m | | DIST2 - Distance | DISTANCE: 8.9012 ft 3.0123 m | STD DEV: 1.2345 ft 0.4567 m And with @CRITERIA as shown above, here's the output: | $ ./reuben2.plx | DIST - Distance | DISTANCE: 12.3456 ft 4.5678 m | STD DEV: 3.4567 ft 1.2345 m | | AREA - Area | AREA: 2345.6789 ft^2 345.6789 m^2 | PERIMETER: 234.5678 ft 89.0123 m | STD DEV: 3.4567 ft 1.2345 m | | DIST - Distance | DISTANCE: 12.3456 ft 4.5678 m | STD DEV: 3.4567 ft 1.2345 m | | DIST - Distance | DISTANCE: 8.9012 ft 3.0123 m | STD DEV: 1.2345 ft 0.4567 m | | DIST2 - Distance | DISTANCE: 8.9012 ft 3.0123 m | STD DEV: 1.2345 ft 0.4567 m The next time you hit a problem like this, you might want to spend more time up-front on specification (and possibly writing test cases and expected outputs) before diving right into the regexes. (Also, remember that Perl offers many different data manipulation techniques; regexes aren't always the right answer.) Happy hacking, t. From tkil at scrye.com Sun Mar 21 01:19:00 2010 From: tkil at scrye.com (Anthony Foiani) Date: Sun, 21 Mar 2010 02:19:00 -0600 Subject: [San-Diego-pm] Recompiling global substitution RE? References: <89038bc01003191535i14d674b0xeabfd4c0940ec5d4@mail.gmail.com> <89038bc01003192214n4b621e11w11bdda1a6d8daf55@mail.gmail.com> Message-ID: Reuben Settergren writes: > [...] is there any way I can force the *left* side to compile > multiple times? (Even within the same /g substitution?) I tried a > few constructs using the \G (start matching from previous position) > zero-width assertion, but only managed to get myself into infinite > loops. It's doable, but it gets ugly to do it flexibly. First, a simple (hardcoded) proof of concept: | #!/usr/bin/perl | | use warnings; | use strict; | | my $orig = "foo1 foo2 foo2 foo3 foo4 foo2 foo5"; | print "orig: $orig\n"; | | my $done = ''; | my $n = 1; | while ( $orig =~ m!\G(.*?)(foo$n)!gc ) | { | $done .= $1; | $done .= 'bar' . $n if defined $2; | ++$n; | } | | print "done: $done\n"; | | exit 0; (Online at: http://scrye.com/~tkil/perl/simple-recomp-replace.plx ) Output: | $ ./simple-recomp-replace.plx | orig: foo1 foo2 foo2 foo3 foo4 foo2 foo5 | done: bar1 bar2 foo2 bar3 bar4 foo2 bar5 Making that generic... I probably didn't do a great job. It might be cleaner if it's implemented as a class; I don't know. Here's what I came up with: | #!/usr/bin/perl | | use warnings; | use strict; | | =over | | =item my $done = recomp_replace $orig, $sub_ref; | | This function provides a relatively generic way to do a global search | and replace while allowing the matching regex to vary. | | =over | | =item $orig | | This is the original string. | | =item $sub_ref | | This is a callback which is fed each matching portion of the $orig | string. Its return value is a list of two items: first, the text to | substitute into the final string; and second, the regex to use to | match the next chunk. | | A special case is when this is called without any arguments; this is | used to obtain the starting regex (and the return text is discarded). | | =back | | Example: | | my $orig = "foo1 foo2 foo2 foo3 foo4 foo2 foo5"; | print "orig: $orig\n"; | | my $n = 0; | sub numbered_foo | { | my ( $chunk ) = @_; | return ( "bar" . $n++, "foo$n" ); | } | | my $done = recomp_replace $orig, \&numbered_foo; | print "done: $done\n"; | | This generates the following output: | | orig: foo1 foo2 foo2 foo3 foo4 foo2 foo5 baz | done: bar1 bar2 foo2 bar3 bar4 foo2 bar5 baz | | For a more complicated example, consider a mini-language that reads in | a mixed list of words and simple directives. This time, the output | first (spacing has been manually adjusted for clarity): | | orig: one=>alpha two one three one two=>beta one two three | done: alpha two alpha three alpha beta one beta three | | And here's the engine behind it: | | my $map_re = qr/ ( \w+ ) => ( \w+ ) /x; | my $last_re = $map_re; | my ( $src, $dest ); | sub selective_map | { | my ( $chunk ) = @_; | my $out; | if ( ! defined $chunk ) | { | $out = ''; | } | elsif ( defined $src && $chunk eq $src ) | { | $out = $dest; | } | elsif ( $chunk =~ /^$map_re$/ ) | { | ( $src, $dest ) = ( $1, $2 ); | $last_re = qr/ $map_re | $src /x; | $out = $dest; | } | return ( $out, $last_re ); | } | | =back | | =cut | | sub recomp_replace | { | my ( $orig, $block ) = @_; | | my $done = ''; | my ( $chunk, $re ) = $block->(); | # print "re='$re'\n"; | my $pos = 0; | while ( $orig =~ m! \G ( .*? ) ( $re ) !gcx ) | { | $done .= $1; | ( $chunk, $re ) = $block->( $2 ); | # print "chunk='$chunk', re='$re'\n"; | $done .= $chunk; | $pos = $+[0]; | } | $done .= substr $orig, $pos; | return $done; | } | | # first example | { | my $orig = "foo1 foo2 foo2 foo3 foo4 foo2 foo5 baz"; | print "orig: $orig\n"; | | my $n = 0; | sub numbered_foo | { | my ( $chunk ) = @_; | return ( "bar" . $n++, "foo$n" ); | } | | my $done = recomp_replace $orig, \&numbered_foo; | print "done: $done\n"; | } | | # second example | { | my $orig = "one=>alpha two one three one two=>beta one two three"; | print "orig: $orig\n"; | | my $map_re = qr/ ( \w+ ) => ( \w+ ) /x; | my $last_re = $map_re; | my ( $src, $dest ); | sub selective_map | { | my ( $chunk ) = @_; | my $out; | if ( ! defined $chunk ) | { | $out = ''; | } | elsif ( defined $src && $chunk eq $src ) | { | $out = $dest; | } | elsif ( $chunk =~ /^$map_re$/ ) | { | ( $src, $dest ) = ( $1, $2 ); | $last_re = qr/ $map_re | $src /x; | $out = $dest; | } | return ( $out, $last_re ); | } | | my $done = recomp_replace $orig, \&selective_map; | print "done: $done\n"; | } | | exit 0; (Online at: http://scrye.com/~tkil/perl/recomp-replace.plx ) Hm. Just realized that the second version will prolly explode if the regex returned from the callback ever matches zero characters (since my "get stuff before the RE" is non-greedy...) Oh well. Don't do that, then. "Share and Enjoy", t. From ruberad at gmail.com Mon Mar 22 11:07:54 2010 From: ruberad at gmail.com (Reuben Settergren) Date: Mon, 22 Mar 2010 11:07:54 -0700 Subject: [San-Diego-pm] Recompiling global substitution RE? In-Reply-To: <89038bc01003192214n4b621e11w11bdda1a6d8daf55@mail.gmail.com> References: <89038bc01003191535i14d674b0xeabfd4c0940ec5d4@mail.gmail.com> <89038bc01003192214n4b621e11w11bdda1a6d8daf55@mail.gmail.com> Message-ID: <89038bc01003221107o63993f14g13984ed031c8e646@mail.gmail.com> I have two ways to solve the problem now. If you're interested, you can fetch a demo script operating on a more realistic (but still fake) example from http://gist.github.com/340326. Thanks for all your help! r On Fri, Mar 19, 2010 at 10:14 PM, Reuben Settergren wrote: > Hi all, > > I've got a Perl problem that's got me stumped. Any help would be > appreciated. > > Consider the following small perl program, which exemplifies a problem I am > having with a script generates HTML sw verification reports, and is supposed > to colorize numbers according to how they verified against what the numbers > are supposed to be. To make things simpler, ?1? > is abbreviated as ?sg1s?: > > #! /bin/perl > $s = "1 2 3 1 2 3 1 2 3"; # what I have > $t = "sg1s 2 3 sr1s 2 3 1 sy2s 3"; # what I want > @nums = qw(1 1 2); > @cols = qw(g r y); > $i=$j=0; > $s =~ s!($nums[$i++])!s$cols[$j++]$1s!g; > print "Want: '$t'\n"; > print "Got: '$s'\n"; > print "i is now $i\n"; > print "j is now $j\n"; > > The output of this program is unfortunately: > > Want: 'sg1s 2 3 sr1s 2 3 1 sy2s 3' > Got: 'sg1s 2 3 sr1s 2 3 sy1s 2 3' > i is now 1 > j is now 3 > > Perl ended up incorrectly coloring the third ?1? yellow, instead of the > third ?2?, because in the substitution regular expression, the left > (matching) side was evaluated/compiled only once, while the right > (replacement) side was evaluated/interpolated three times (as desired). > > I know that there are ways to force the left side of the RE to compile only > once (/o modifier, qr// operator), and there are ways to force eval in the > right side (/e and /ee modifiers ? although in this case, standard > interpolation was sufficient), but is there any way I can force the *left* side > to compile *multiple* times? (Even within the same /g substitution?) I > tried a few constructs using the \G (start matching from previous position) > zero-width assertion, but only managed to get myself into infinite loops. > > I'd appreciate any help anyone can offer -- including "What an idiot, the > RIGHT way to do that is completely different! (And here it is...)" > > thx for thinking for me! > > r > > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rkleeman at energoncube.net Tue Mar 23 16:45:38 2010 From: rkleeman at energoncube.net (Bob Kleemann) Date: Tue, 23 Mar 2010 16:45:38 -0700 Subject: [San-Diego-pm] Damian Conway is coming Message-ID: Perl Mongers, Perl Icon Damian Conway is coming to educate and entertain us! We're still nailing down the date, time, and other details, but pencil in Thursday, April 8th, 8 PM - ??? at the Qualcomm Auditorium. Topics have been narrowed down to the following four: ? ?http://damian.conway.org/Seminars/MissingLink.html http://damian.conway.org/Seminars/Quaquaversal.html http://damian.conway.org/Seminars/ReDeveloping.html ? ?http://damian.conway.org/Seminars/Twilight.html If you're interested in helping choose the topic, please rank the above in the order you'd like to see them. I'll tabulate the votes and pick the most popular. Please let me know if you have any questions or other thoughts. From the.hippsta at gmail.com Tue Mar 23 17:14:45 2010 From: the.hippsta at gmail.com (hippsta) Date: Tue, 23 Mar 2010 17:14:45 -0700 Subject: [San-Diego-pm] Damian Conway is coming In-Reply-To: References: Message-ID: "http://damian.conway.org/Seminars/Twilight.html" For a split second I was like "WTF no way! no you guys too!?!?" lol :) On Tue, Mar 23, 2010 at 4:45 PM, Bob Kleemann wrote: > Perl Mongers, > > Perl Icon Damian Conway is coming to educate and entertain us! We're > still nailing down the date, time, and other details, but pencil in > Thursday, April 8th, 8 PM - ??? at the Qualcomm Auditorium. > > Topics have been narrowed down to the following four: > > http://damian.conway.org/Seminars/MissingLink.html > http://damian.conway.org/Seminars/Quaquaversal.html > http://damian.conway.org/Seminars/ReDeveloping.html > http://damian.conway.org/Seminars/Twilight.html > > If you're interested in helping choose the topic, please rank the > above in the order you'd like to see them. I'll tabulate the votes > and pick the most popular. > > Please let me know if you have any questions or other thoughts. > _______________________________________________ > San-Diego-pm mailing list > San-Diego-pm at pm.org > http://mail.pm.org/mailman/listinfo/san-diego-pm > -- Respectfully, Chris Hart Systems Administrator Extrameasures, LLC. 8910 University Center Lane, Suite 475 San Diego, CA 92122 -------------- next part -------------- An HTML attachment was scrubbed... URL: From xrz1138 at gmail.com Tue Mar 23 18:17:18 2010 From: xrz1138 at gmail.com (Christopher Hahn) Date: Tue, 23 Mar 2010 18:17:18 -0700 Subject: [San-Diego-pm] Damian Conway is coming In-Reply-To: References: Message-ID: Well, that was the last reason this lurker came out of the shadows....and I will again. Thank you for the info! Chris On Tue, Mar 23, 2010 at 4:45 PM, Bob Kleemann wrote: > Perl Mongers, > > Perl Icon Damian Conway is coming to educate and entertain us! ?We're > still nailing down the date, time, and other details, but pencil in > Thursday, April 8th, 8 PM - ??? at the Qualcomm Auditorium. > > Topics have been narrowed down to the following four: > > ?? ??http://damian.conway.org/Seminars/MissingLink.html > ? ? http://damian.conway.org/Seminars/Quaquaversal.html > ? ? http://damian.conway.org/Seminars/ReDeveloping.html > ?? ?http://damian.conway.org/Seminars/Twilight.html > > If you're interested in helping choose the topic, please rank the > above in the order you'd like to see them. ?I'll tabulate the votes > and pick the most popular. > > Please let me know if you have any questions or other thoughts. > _______________________________________________ > San-Diego-pm mailing list > San-Diego-pm at pm.org > http://mail.pm.org/mailman/listinfo/san-diego-pm > -- Realisant mon espoir, je me lance vers la gloire. Christopher Hahn == xrz1138 at gmail.com From saaib at ciberlinux.net Tue Mar 23 21:53:55 2010 From: saaib at ciberlinux.net (Urivan Flores) Date: Tue, 23 Mar 2010 20:53:55 -0800 Subject: [San-Diego-pm] Damian Conway is coming In-Reply-To: References: Message-ID: <20100324045155.M2785@ciberlinux.net> Bob, Suggesting re-arranging as follows: 1. http://damian.conway.org/Seminars/ReDeveloping.html 2. http://damian.conway.org/Seminars/Twilight.html 3.?http://damian.conway.org/Seminars/MissingLink.html 4. http://damian.conway.org/Seminars/Quaquaversal.html Regards, -- Urivan Flores-Saaib saaib at ciberlinux.net (858) 431-9734 From xrz1138 at gmail.com Tue Mar 23 22:15:11 2010 From: xrz1138 at gmail.com (Christopher Hahn) Date: Tue, 23 Mar 2010 22:15:11 -0700 Subject: [San-Diego-pm] Damian Conway is coming In-Reply-To: <20100324045155.M2785@ciberlinux.net> References: <20100324045155.M2785@ciberlinux.net> Message-ID: "..a head-trip through a dozen or so arcane and sinister ?features? of Perl." This one is for me! 1. http://damian.conway.org/Seminars/Twilight.html 2. http://damian.conway.org/Seminars/ReDeveloping.html 3. http://damian.conway.org/Seminars/MissingLink.html 4. http://damian.conway.org/Seminars/Quaquaversal.html On Tue, Mar 23, 2010 at 9:53 PM, Urivan Flores wrote: > Bob, > > Suggesting re-arranging as follows: > > 1. http://damian.conway.org/Seminars/ReDeveloping.html > 2. http://damian.conway.org/Seminars/Twilight.html > 3.?http://damian.conway.org/Seminars/MissingLink.html > 4. http://damian.conway.org/Seminars/Quaquaversal.html > > > Regards, > > -- > Urivan Flores-Saaib > saaib at ciberlinux.net > (858) 431-9734 > > _______________________________________________ > San-Diego-pm mailing list > San-Diego-pm at pm.org > http://mail.pm.org/mailman/listinfo/san-diego-pm -- Realisant mon espoir, je me lance vers la gloire. Christopher Hahn == xrz1138 at gmail.com From rlssdpm at schnapp.org Wed Mar 24 11:38:54 2010 From: rlssdpm at schnapp.org (Russ Schnapp) Date: Wed, 24 Mar 2010 11:38:54 -0700 Subject: [San-Diego-pm] Damian Conway is coming In-Reply-To: References: Message-ID: <4BAA5C3E.3050703@schnapp.org> My preferences would be: MissingLink Twilight Quaquaversal ReDeveloping (last choice only because previous talk was on Perl 6) > http://damian.conway.org/Seminars/MissingLink.html > http://damian.conway.org/Seminars/Quaquaversal.html > http://damian.conway.org/Seminars/ReDeveloping.html > http://damian.conway.org/Seminars/Twilight.html From daniel at danielnorman.net Wed Mar 24 17:06:32 2010 From: daniel at danielnorman.net (Daniel Norman) Date: Wed, 24 Mar 2010 17:06:32 -0700 Subject: [San-Diego-pm] Damian Conway is coming In-Reply-To: References: Message-ID: <4BAAA908.8050607@danielnorman.net> Here's my vote: 1 ReDeveloping 2 Twilight 3 MissingLink 4 undef On 03/23/2010 04:45 PM, Bob Kleemann wrote: > Perl Mongers, > > Perl Icon Damian Conway is coming to educate and entertain us! We're > still nailing down the date, time, and other details, but pencil in > Thursday, April 8th, 8 PM - ??? at the Qualcomm Auditorium. > > Topics have been narrowed down to the following four: > > http://damian.conway.org/Seminars/MissingLink.html > http://damian.conway.org/Seminars/Quaquaversal.html > http://damian.conway.org/Seminars/ReDeveloping.html > http://damian.conway.org/Seminars/Twilight.html > > If you're interested in helping choose the topic, please rank the > above in the order you'd like to see them. I'll tabulate the votes > and pick the most popular. > > Please let me know if you have any questions or other thoughts. > _______________________________________________ > San-Diego-pm mailing list > San-Diego-pm at pm.org > http://mail.pm.org/mailman/listinfo/san-diego-pm > From the.hippsta at gmail.com Wed Mar 24 17:52:07 2010 From: the.hippsta at gmail.com (hippsta) Date: Wed, 24 Mar 2010 17:52:07 -0700 Subject: [San-Diego-pm] Damian Conway is coming In-Reply-To: <4BAAA908.8050607@danielnorman.net> References: <4BAAA908.8050607@danielnorman.net> Message-ID: Just in case mine was shrouded in ambiguity: 1 Twilight 2,3,4 undef I really want to come to this one! :) hip. On Wed, Mar 24, 2010 at 5:06 PM, Daniel Norman wrote: > Here's my vote: > > 1 ReDeveloping > 2 Twilight > 3 MissingLink > 4 undef > > > > On 03/23/2010 04:45 PM, Bob Kleemann wrote: > >> Perl Mongers, >> >> Perl Icon Damian Conway is coming to educate and entertain us! We're >> still nailing down the date, time, and other details, but pencil in >> Thursday, April 8th, 8 PM - ??? at the Qualcomm Auditorium. >> >> Topics have been narrowed down to the following four: >> >> http://damian.conway.org/Seminars/MissingLink.html >> http://damian.conway.org/Seminars/Quaquaversal.html >> http://damian.conway.org/Seminars/ReDeveloping.html >> http://damian.conway.org/Seminars/Twilight.html >> >> If you're interested in helping choose the topic, please rank the >> above in the order you'd like to see them. I'll tabulate the votes >> and pick the most popular. >> >> Please let me know if you have any questions or other thoughts. >> _______________________________________________ >> San-Diego-pm mailing list >> San-Diego-pm at pm.org >> http://mail.pm.org/mailman/listinfo/san-diego-pm >> >> > > _______________________________________________ > San-Diego-pm mailing list > San-Diego-pm at pm.org > http://mail.pm.org/mailman/listinfo/san-diego-pm > -- Respectfully, Chris Hart Systems Administrator Extrameasures, LLC. 8910 University Center Lane, Suite 475 San Diego, CA 92122 -------------- next part -------------- An HTML attachment was scrubbed... URL: From menolly at mib.org Thu Mar 25 10:17:13 2010 From: menolly at mib.org (Menolly) Date: Thu, 25 Mar 2010 10:17:13 -0700 (PDT) Subject: [San-Diego-pm] Damian Conway is coming In-Reply-To: References: <4BAAA908.8050607@danielnorman.net> Message-ID: That's about how I feel, too -- I'll come regardless, but Twilight Zone was the only one that stood out to me. On Wed, 24 Mar 2010, hippsta wrote: > Just in case mine was shrouded in ambiguity: > > 1 Twilight > 2,3,4 undef > > I really want to come to this one! :) > > hip. > > On Wed, Mar 24, 2010 at 5:06 PM, Daniel Norman wrote: > Here's my vote: > > 1 ReDeveloping > 2 Twilight > 3 MissingLink > 4 undef > > > > On 03/23/2010 04:45 PM, Bob Kleemann wrote: > Perl Mongers, > > Perl Icon Damian Conway is coming to educate and entertain us! ?We're > still nailing down the date, time, and other details, but pencil in > Thursday, April 8th, 8 PM - ??? at the Qualcomm Auditorium. > > Topics have been narrowed down to the following four: > > ? ? ?http://damian.conway.org/Seminars/MissingLink.html > ? ? ?http://damian.conway.org/Seminars/Quaquaversal.html > ? ? ?http://damian.conway.org/Seminars/ReDeveloping.html > ? ? ?http://damian.conway.org/Seminars/Twilight.html > > If you're interested in helping choose the topic, please rank the > above in the order you'd like to see them. ?I'll tabulate the votes > and pick the most popular. > > Please let me know if you have any questions or other thoughts. > _______________________________________________ > San-Diego-pm mailing list > San-Diego-pm at pm.org > http://mail.pm.org/mailman/listinfo/san-diego-pm > ? > > > _______________________________________________ > San-Diego-pm mailing list > San-Diego-pm at pm.org > http://mail.pm.org/mailman/listinfo/san-diego-pm > > > > > -- > Respectfully, > > Chris Hart > Systems Administrator > Extrameasures, LLC. > 8910 University Center Lane, Suite 475 > San Diego, CA ?92122 > > > -- menolly at mib.org http://www.livejournal.com/~nolly/ On that day, many will say to me, "Lord, Lord, did we not prophesy in your name, and cast out demons in your name, and do many mighty works in your name?" And then will I declare to them, "I never knew you; depart from me you evildoers." -- Matt 7:20-23, RSV From rkleeman at energoncube.net Fri Mar 26 09:53:14 2010 From: rkleeman at energoncube.net (Bob Kleemann) Date: Fri, 26 Mar 2010 09:53:14 -0700 Subject: [San-Diego-pm] Google Summer of Code and TPF call for students (fwd) In-Reply-To: <201003260350.55273.scratchcomputing@gmail.com> References: <201003260350.55273.scratchcomputing@gmail.com> Message-ID: ---------- Forwarded message ---------- From: Eric Wilhelm Date: Fri, Mar 26, 2010 at 3:50 AM Subject: Google Summer of Code and TPF call for students Hi Perl Mongers, TPF is participating in GSoC 2010 and will begin accepting applications from students on the 29th. ?Please share this info with your groups and local academic contacts. If you are a college student interested in Open Source software, now is the time to get involved. ?http://code.google.com/soc/ Each year, Google offers students the opportunity to spend their summer coding on open source projects. You propose a project, and if selected, you're assigned a mentor and provided a $4500 stipend. It is a competitive program to get into, but offers an amazing amount of real-world experience and the ability to get seriously involved in an open source project of your choosing. The Perl Foundation spans a wide variety of projects including Perl 5, Perl 6, and Parrot with many great mentors knowledgeable in areas ranging from language design, virtual machines, and compilers through web and desktop applications. This program is a great chance to get more involved in the Perl community and put a substantial project worth of source code in your portfolio. Applications are due April 9th. ?http://www.perlfoundation.org/perl5/index.cgi?gsoc Thanks, Eric -- http://pdx.pm.org -- Request pm.org Technical Support via support at pm.org pm_groups mailing list pm_groups at pm.org http://mail.pm.org/mailman/listinfo/pm_groups From rkleeman at energoncube.net Tue Mar 30 13:35:36 2010 From: rkleeman at energoncube.net (Bob Kleemann) Date: Tue, 30 Mar 2010 13:35:36 -0700 Subject: [San-Diego-pm] March Mingle Message-ID: Hello Perl Mongers, Just a quick reminder that the March Mingle event is tonight! You can find all the details at http://MarchMingle.com/. Please RSVP if you haven't already, and I look forward to seeing everyone there!