3 problems with perl.

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
1. , I'm having problem with balanced parenthesis. I found this code in
the net:
my $paren = qr/\(([^()]+|(??{ $paren }))*\)/x;
This code supposes to handle my problem.
I'm working with perl 5.8, and it won't compile.
The error message is: "Global symbol "$paren" requires explicit package
name at (re_eval 1) line 2.".

2. How can I Use constants and variables inside a substitute operator

3. Manipulate matched chars. When matched a number I need to add the
same value to each matched chararcter.

Re: 3 problems with perl.

nimrodna wrote:

Quoted text here. Click to load it

Please put the subject of your post in the Subject of your post.

If you have 3 separate subjects, make 3 separate posts.

Quoted text here. Click to load it

How is that relevant?

Quoted text here. Click to load it

Appart from the suprious my() this same code can be found in "perlre"
the section  of the Perl on-line documentation that covers regular

Quoted text here. Click to load it

That's right. Lexically scoped variable declarations apply from the
point after declaration statement to the end of the lexical scope.  You
cannot refer to the variable _within_ the statement in which it is

Note also that (??{ ... }) blocks suffer from the same problem as
nested subroutines with respect to lexical variables.  (See perldiag's
explaination of the "will not remain shared" warning).

Avoid this by using only package variables when communicating with
(??) blocks.

local our $paren;
$paren = qr/\(([^()]+|(??{ $paren }))*\)/x;

Quoted text here. Click to load it

Variables interpolate just like they do in double-qouted strings.

Constants are functions and can be interpolated as per the FAQ "How do
I expand function calls in a string?". Hmmm perhaps it's about time to
try again submitting a doc patch to change the unhelpful word "expand"
to "interpolate".

Quoted text here. Click to load it

Sorry, I can't understand what you mean by add a value to a character.

In Perl regular expressions you can use () to capture stuff into
special variables and you can then use those variables in expressions
to calculate values.

Re: 3 problems with perl.

Brian McCauley wrote:
Quoted text here. Click to load it

Sorry that's a bit confused.  What I meant was that you were having a
problem with variable declarations and recursive pattern matches. The
problem that you were trying to solve with the recursive pattern is not
actually part of the problem.

Consider, if you will, an analogy.  if your car breaks down on the way
to work you have a problem getting to work. But this is not relevant to
how you fix the car.
Correctly partitioning your problem is a very important first step to
soving it.

Site Timeline