954,541 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Comparing items in arrays

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

for $3 (@obsolete_class_declare)         
{
    for $4 (@classB)
    {
        if ($4 =~ /$3/i)          #This line causing problem
        {
            print "$4\n";
            last;
        }
    }
    
}
raul15791
Junior Poster
102 posts since Jun 2008
Reputation Points: 37
Solved Threads: 7
 

I found the problem already. I put "**" in the arrays which causes some data reading problem. Solved!

raul15791
Junior Poster
102 posts since Jun 2008
Reputation Points: 37
Solved Threads: 7
 

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.

KevinADC
Posting Shark
921 posts since Mar 2006
Reputation Points: 246
Solved Threads: 67
 

Thanks for the info!

raul15791
Junior Poster
102 posts since Jun 2008
Reputation Points: 37
Solved Threads: 7
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You