Hi Rob, Thanks a lot for the reply. It served my purpose. Sorry for giving incomplete information. I just want to use the subst() module, by passing an array.
The problem was I added [] for each record in the array, as follows. my @subs = ( [qr/\{(.*?)\}/ => '$1'], [qr/_(\w+)_/ => '<u>\$1</u>'], [qr/<(\w+)>/ => '<i>$1</i>'] ); I also tried the same syntax in the push operation. my @subs; push @subs_array, [qr/\{(.*?)\}/ , '$1'] ; push @subs_array, [qr/_(\w+)_/ , '<u>\$1</u>'] ; push @subs_array, [qr/<(\w+)>/ , '<i>$1</i>'] ; Now after you have mentioned, I tried without the []. It works as expected in both cases. Thanks once again for helping me in this, as I was getting frustrated and distracted not knowing the correct syntax the subst() will understand. Thanks & Regards, Raja -----Original Message----- From: Rob Dixon [mailto:[EMAIL PROTECTED] Sent: Wednesday, March 26, 2003 2:39 PM To: [EMAIL PROTECTED] Subject: Re: Array creatiion methods 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]
**************************Disclaimer************************************************ Information contained in this E-MAIL being proprietary to Wipro Limited is 'privileged' and 'confidential' and intended for use only by the individual or entity to which it is addressed. You are notified that any use, copying or dissemination of the information contained in the E-MAIL in any manner whatsoever is strictly prohibited. ***************************************************************************************
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]