develooper Front page | perl.perl5.porters | Postings from May 2003

Re: [perl #22238] <$foo> is parsed as glob(' ' . $foo) if is used

Thread Next
Ronald J Kimball
May 19, 2003 14:53
Re: [perl #22238] <$foo> is parsed as glob(' ' . $foo) if is used
Message ID:
On Mon, May 19, 2003 at 11:06:46PM +0200, Rafael Garcia-Suarez wrote:

>   Michael Fowler reported a weird parsing bug (#22231) caused by the
>   presence of the Switch module in a program, and of a comment
>   containing the word "switch".

I replied to this bug on (because I'd deleted the original
report), but my reply hasn't shown up on p5p, and isn't
showing my attachment, so I'll try again through email...

The parsing error is introduced by the following section of code in

    @pos = Text::Balanced::_match_variable(\$source,qr/\s*/);
    if (defined $pos[0])
        $text .= " " . substr($source,$pos[0],$pos[4]-$pos[0]);
        next component;

As you can see, when matching a variable, the filter adds a space to the
text, even if no space was present in the original source.  Thus, <$foo>
becomes < $foo>, which perl interprets as glob(' ' . $foo) instead of

(Also note that Switch uses private methods of Text::Balanced.  Tsk tsk!)

This patch should fix the behavior, by making the filter add a space
character to the text iff the original source has one or more whitespace
characters there.  I made the same change everywhere a space was being
added after using a Text::Balanced method.


Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About