[Melbourne-pm] Regexps - how does the lexical scope of capture buffers work? (Was: Regexp: What's the right way to do this?)

Michael G Schwern schwern at pobox.com
Wed Oct 17 15:46:45 PDT 2012


On 2012.10.17 2:33 PM, Peter Vereshagin wrote:
> The what is wrong with this:

Very clever.  Now match the contents of <p class="summary"> and <p
class="description"> and associate all three pieces of data together.

(It finds all div's with the proper content rather than just the ones of the
event-time calendar class, but that's a fairly trivial fix.)


>     #!/usr/bin/env perl
>     use strict;
>     use warnings;
>     use autodie;
> 
>     my $str = '';
>     while ( my $buf .= <DATA> ) {
>         $str .= $buf;
>         if (my ( $hh_mm_start => $hh_mm_end )
>             = $str =~ m/
>                 <div[^>]*>\s*
>                 (\d\d?:\d\d?)
>                 \s*-\s*
>                 (\d\d?:\d\d?)
>                 /sx
>             )
>         {
>             use Data::Dump;
>             ddx $hh_mm_start => $hh_mm_end;
>             $str = '';
>         }
>     }


-- 
Life is like a sewer - what you get out of it depends on what you put into it.
    - Tom Lehrer


More information about the Melbourne-pm mailing list