[Melbourne-pm] Regexps - how does the lexical scope of capture buffers work? (Was: Regexp: What's the right way to do this?)
Shlomi Fish
shlomif at shlomifish.org
Wed Oct 17 04:38:26 PDT 2012
Hi Nathan,
On Wed, 17 Oct 2012 21:36:56 +1100
Nathan Bailey <nathan.bailey at monash.edu> wrote:
> I really wish I had obfuscated the contents of the regexps :-(
>
> My question, which I thought I had clearly stated, related to the
> lexical scope of capture buffers, and why one approach to capture
> buffers worked and another didn't.
>
> Let's try again:
> #if (($start_time) = m#^\s*(\d+:\d+) -#) {
> if (m#^\s*(\d+:\d+) -#) {
> $start_time = $2;
> #} elsif (($finish_time) = m#^\s*(\d+:\d+)#) {
> } elsif (m#^\s*(\d+:\d+)#) {
> $finish_time = $1;
> $event++;
> }
>
> Why is $start_time undefined when we get to $finish_time in the first
> version (commented out) and not in the second?
>
> And is there a good/better way to collect multiple values over
> multiple lines than this?
>
Your code is hard to follow. Can you post a reproducing example for the issue
you're trying to resolve, without the need to uncomment stuff? You can also
post a working and non-working version.
Regards,
Shlomi Fish
> thanks,
> Nathan
--
-----------------------------------------------------------------
Shlomi Fish http://www.shlomifish.org/
Stop Using MSIE - http://www.shlomifish.org/no-ie/
But if you're writing [open source software] for the world, you have to listen
to your customers — this doesn't change just because they're not paying you in
money.
— Eric S. Raymond in The Cathedral and the Bazaar
Please reply to list if it's a mailing list post - http://shlom.in/reply .
More information about the Melbourne-pm
mailing list