Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Stubborn regex :-(

Reply
Thread Tools

Stubborn regex :-(

 
 
Frostillicus
Guest
Posts: n/a
 
      10-28-2004
I'm having trouble getting a regex to evaluate to true, even though it looks
plainly obvious to me that it should be. Here's what I'm doing...

print "find=" . $form{'find'} . ";name=" . $hashref->{'name'};


This line of code prints the following for an example set of data...

find=ant;name=The Ant's Pants.


Here's the code...

my $temp = $hashref->{'name'};

if ($form{'find'} =~ /$temp/i) {
print "Found record!";
}



You might say that I shouldn't need to stuff the hashref into a $temp
variable, but I did that in desperation in case some bizarre problem has
preventing me from matching on a value inside a reference to a hash.


 
Reply With Quote
 
 
 
 
Frostillicus
Guest
Posts: n/a
 
      10-28-2004
Hmm, my bad... If I swap the variables around, voilas! Grrrrr!




"Frostillicus" <(E-Mail Removed)> wrote in message
news:4180a689$0$13746$(E-Mail Removed)...
> I'm having trouble getting a regex to evaluate to true, even though it

looks
> plainly obvious to me that it should be. Here's what I'm doing...
>
> print "find=" . $form{'find'} . ";name=" . $hashref->{'name'};
>
>
> This line of code prints the following for an example set of data...
>
> find=ant;name=The Ant's Pants.
>
>
> Here's the code...
>
> my $temp = $hashref->{'name'};
>
> if ($form{'find'} =~ /$temp/i) {
> print "Found record!";
> }
>
>
>
> You might say that I shouldn't need to stuff the hashref into a $temp
> variable, but I did that in desperation in case some bizarre problem has
> preventing me from matching on a value inside a reference to a hash.
>
>



 
Reply With Quote
 
 
 
 
Arndt Jonasson
Guest
Posts: n/a
 
      10-28-2004

"Frostillicus" <(E-Mail Removed)> writes:
> I'm having trouble getting a regex to evaluate to true, even though it looks
> plainly obvious to me that it should be. Here's what I'm doing...
>
> print "find=" . $form{'find'} . ";name=" . $hashref->{'name'};
>
>
> This line of code prints the following for an example set of data...
>
> find=ant;name=The Ant's Pants.
>
>
> Here's the code...
>
> my $temp = $hashref->{'name'};
>
> if ($form{'find'} =~ /$temp/i) {
> print "Found record!";
> }


I think you want the operands of =~ the other way around. What the
above amounts to is

if ("ant" =~ /The Ant's Pants/i) {
print "Found record!";
}
 
Reply With Quote
 
Paul Lalli
Guest
Posts: n/a
 
      10-28-2004
Frostillicus wrote:
> "Frostillicus" <(E-Mail Removed)> wrote in message
> news:4180a689$0$13746$(E-Mail Removed)...
>
>>
>>print "find=" . $form{'find'} . ";name=" . $hashref->{'name'};
>>
>>This line of code prints the following for an example set of data...
>>find=ant;name=The Ant's Pants.
>>
>>
>>Here's the code...
>>
>>my $temp = $hashref->{'name'};
>>
>>if ($form{'find'} =~ /$temp/i) {
>> print "Found record!";
>>}
>>
>>You might say that I shouldn't need to stuff the hashref into a $temp
>>variable, but I did that in desperation in case some bizarre problem has
>>preventing me from matching on a value inside a reference to a hash.
>>

> Hmm, my bad... If I swap the variables around, voilas! Grrrrr!


For future reference, it is sometimes helpful to read the =~ as
"contains" rather than "matches". If you do that, your original
statement reads:
if 'ant' contains "The Ant's Pants" then print 'Found Record!'.

If you read it allowed like this, it becomes obvious that the
'containment' is reversed.

Paul Lalli
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How make regex that means "contains regex#1 but NOT regex#2" ?? seberino@spawar.navy.mil Python 3 07-01-2008 03:06 PM
Re: Ejecting stubborn thanatoid - was - Re: Ejecting stubborn CD thanatoid Computer Support 0 03-29-2007 12:03 AM
Firefox 1.5 being stubborn with some links RyeTronics Firefox 6 01-13-2006 06:42 PM
A very stubborn private static member steve.chambers@gmail.com Java 20 08-12-2005 08:41 AM
Stubborn Address Bar drop down list...how do I rid the listed items. MC Computer Support 7 06-01-2004 09:05 AM



Advertisments