Hi Raja.

Raja Kasinathan wrote:
>
>       I am trying to use the CPAN module Regexp::Subst::Parallel.
> The example code given in the documentation is
>
>     $text = '{process_the_data} was _called_ without <data>!';
>     $text = subst($text,
>                 qr/\{(.*?)\}/ => '$1',  # Protect things in braces
>                 qr/_(\w+)_/   => '<u>$1</u>',
>                 qr/<(\w+)>/   => '<i>$1</i>',
>             );
>
> Inside the subst(), a scalar and an array are populated using the passed
> arguments as follows:
> (
> <http://search.cpan.org/src/LPALMER/Regexp-Subst-Parallel-0.10/Parallel.
> pm>
> http://search.cpan.org/src/LPALMER/Regexp-Subst-Parallel-0.10/Parallel.p
> m )
>
>
>     my $str = shift;
>     my @subs;
>     while (@_) {
>         push @subs, [ shift, shift ];
>     }
>
> Instead of the above, I tried to create a global array outside and use
> it inside the subst().

Are you saying that you've rewritten the module? That would make me
frown quite a lot. You wouldn't like me when I'm frowning!

> (For simplicity of the discussion, I am avoiding passing the array by
> value or reference.)

If this isn't what you're really doing then we need to know what that is!

> my $text = '{process_the_data} was _called_ without <data>! ;
>
> my @subs = ( [qr/\{(.*?)\}/ => '$1'],
>
>              [qr/_(\w+)_/ => '<u>\$1</u>'],
>
>              [qr/<(\w+)>/ => '<i>$1</i>'] );

Right. This creates a lexical array (not a global one as you said) which
looks the same as the one that subst() would build when it was called.

> $text = subst($text);

And this calls subst() with only one argument, which will then simply
return that argument unchanged.

> This doesn't work exactly as the previous one. Runs indefinite loop in
> the '<u>\$1</u>'.

You're doing something you haven't told us about.

> If I remove that expression, it works partially. So I would like to know
> the difference between
> these 2 methods of creating arrays. I appreciate your time and efforts
> in helping to solve this problem.


The difference is that one is local to Regexp::Subst::Parallel::subst and
the other is local to the calling code. It still sounds like you've modified
the module, in which case I can claim that the customer has tampered
with the goods and the warranty is therefore null and void!

You need to tell us more about what's going on. There's no need to
'simplify' anything as it will only serve to confound us, and there's
been some quite opaque code posted here before!

If my guess is right about what you're doing, wouldn't it serve your purpose
to leave the module as it is and call it like this?

    my @subs = (
        qr/\{(.*?)\}/ => '$1',
        qr/_(\w+)_/ => '<u>\$1</u>',
        qr/<(\w+)>/ => '<i>$1</i>',
    );

    $text = subst( $text, @subs );

Cheers,

Rob




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to