Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't get variable regex to match??? This should be easy

Status
Not open for further replies.

sapatos

Programmer
Jan 20, 2006
57
AU
Hi,

I've got a loop that is searching an array for a match. When I hardcode the search pattern it works great but when I pass the search pattern in as a variable it doesn't find anything. Can someone advise?

Code is:

foreach my $search (@searchStrings) {


print "string: $search\n";
@holder = grep(!m/$search/,@mainFile);
print "size stripped: " . @holder . "\n";
print "size orig: " . @mainFile . "\n";

}

if I replace the grep line with:

@holder = grep(!m/VT02382933451687/,@mainFile);

it matches?

thanks
 
It really depends on what you have in @searchStrings. Do you have trailing newlines perhaps? Try chomping @searchStrings before the loop maybe?

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
hi steve,

thanks for that. I actually spotted that just after i hit send in the forum. typical ;(

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top