Click here to get back home

3 problems with perl.

 HomeNewsGroups | Search | About
 comp.lang.perl.misc    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
3 problems with perl. nimrodna 09-02-2006
Posted by nimrodna on September 2, 2006, 1:35 pm
Please log in for more thread options
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
(s///).

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


Posted by Brian McCauley on September 2, 2006, 1:58 pm
Please log in for more thread options

nimrodna wrote:

> Subject: 3 problems with perl.

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

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

> 1. , I'm having problem with balanced parenthesis.

>Are you?

How is that relevant?

> I found this code in
> the net:
> my $paren = qr/\(([^()]+|(??{ $paren }))*\)/x;
> This code supposes to handle my problem.

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

> 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.".

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
declared.

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;

> 2. How can I Use constants and variables inside a substitute operator
> (s///).

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".

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

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.


Posted by Brian McCauley on September 2, 2006, 2:11 pm
Please log in for more thread options

Brian McCauley wrote:
> nimrodna wrote:
> > 1. , I'm having problem with balanced parenthesis.
>
> >Are you?
>
> How is that relevant?

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.


Similar ThreadsPosted
Problems with PERL CGI March 31, 2006, 5:17 pm
perl ftp problems February 15, 2007, 12:38 pm
Problems with Perl 5.10 on Mac OS 10.5.2 March 21, 2008, 3:44 pm
Perl Script Problems January 24, 2005, 3:46 am
Problems Installing perl 5.8.7 November 9, 2005, 7:03 am
Problems Installing perl 5.8.7 November 9, 2005, 7:03 am
Problems after updating Net::SSH:Perl March 2, 2006, 10:56 am
Problems installing DBI module on perl August 9, 2004, 10:40 am
problems with Perl RegEx match December 27, 2004, 5:07 pm
Perl and SMTP mail problems June 23, 2005, 5:12 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap