Re: "my" variables and recursive regexp strangeness

From: Anno Siegel (anno4000_at_lublin.zrz.tu-berlin.de)
Date: 05/13/04


Date: 13 May 2004 14:00:55 GMT

Ian <ijnetnews@hotmail.com> wrote in comp.lang.perl.misc:
> I have something strange happening with a recursive regexp compiled
> with qr//x; It is a regular expression to match individual single
> double and un-quoted strings, i.e. "string", 'string' and string.
>
> It works fine when the sub parts of it are global variables, or
> "local" variables, but if I change them to "my" variables, suddenly
> they stop matching correctly (or at least start matching differently).
>
> Anybody have any ideas why changing to "my" variables would affect it
> this way?

It isn't the fact that they're lexical, but you apparently tried
to declare the variables in the same statement that uses them,
as in

    my $dStringData = qr/
        ([^"\\]|\\.)+ (??{$dStringData})
        |
        "
    /x;

You can't use a lexical in the same statement that declares it.
Use an extra "my" statement, and it works.

It would have been better to post the erroneous code, instead of
saying "if I change this, it doesn't work anymore". That way
we wouldn't have to guess your error.

Anno



Relevant Pages

  • Re: OnTimer event-Form does not load:Here is the code
    ... global variables which are declared in another module. ... you might want to do declare and populate them ... >Private Sub Form_Timer ... > Dim strErrorMsg As String ...
    (microsoft.public.access.forms)
  • Re: Working with SUBs
    ... Module-level variables are declared *before* the first Sub or Function in the module. ... A module level variable can be used by any routine within the same module. ... Global variables are also declared before the first Sub or Function of a module, ... If you declare a variable locally and pass it as a parameter to another routine, you know that there is only one point at which the two routines interact. ...
    (microsoft.public.word.vba.general)
  • Declare Variable
    ... Declare your global variables at the top of ... not inside the SetRefs proc. ... Private Sub Workbook_Open ...
    (microsoft.public.excel.programming)
  • Re: "my" variables and recursive regexp strangeness
    ... Ian wrote: ... > I have something strange happening with a recursive regexp compiled ... > It works fine when the sub parts of it are global variables, ...
    (comp.lang.perl.misc)
  • Calendar Object
    ... it won't allow me to declare the global variables ... >>Still create the Calendar form. ... >>The calendar Form should have the following Sub ...
    (microsoft.public.access.reports)