Comparing items in arrays

Please support our Perl advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Jun 2008
Posts: 89
Reputation: raul15791 is an unknown quantity at this point 
Solved Threads: 7
raul15791 raul15791 is offline Offline
Junior Poster in Training

Comparing items in arrays

 
0
  #1
Jul 9th, 2008
Hi,

I try to compare items in two different arrays. This loop works well in another program of mine. But not in the current program i'm working on. Weird....

The output of the program shows
Nested quantifiers in regex; marked by <-- HERE........
  1. for $3 (@obsolete_class_declare)
  2. {
  3. for $4 (@classB)
  4. {
  5. if ($4 =~ /$3/i) #This line causing problem
  6. {
  7. print "$4\n";
  8. last;
  9. }
  10. }
  11.  
  12. }
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 89
Reputation: raul15791 is an unknown quantity at this point 
Solved Threads: 7
raul15791 raul15791 is offline Offline
Junior Poster in Training

Re: Comparing items in arrays

 
0
  #2
Jul 9th, 2008
I found the problem already. I put "**" in the arrays which causes some data reading problem. Solved!
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 898
Reputation: KevinADC has a spectacular aura about KevinADC has a spectacular aura about 
Solved Threads: 67
KevinADC's Avatar
KevinADC KevinADC is offline Offline
Practically a Posting Shark

Re: Comparing items in arrays

 
0
  #3
Jul 9th, 2008
You should not use numbered scalar variables in your perl programs, $1 and $2 and etc are used internally by perl for pattern memory and are read only. If you have meta characters in your array elements just use the \Q option to escape them:

$foo =~ /\Q$bar/;

stuff like ** will be interpreted literally, but $ and @ will still be treated like a variable and interpolated.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 89
Reputation: raul15791 is an unknown quantity at this point 
Solved Threads: 7
raul15791 raul15791 is offline Offline
Junior Poster in Training

Re: Comparing items in arrays

 
0
  #4
Jul 9th, 2008
Thanks for the info!
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 1287 | Replies: 3
Thread Tools Search this Thread



Tag cloud for Perl
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC