CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Trouble Matching numeric value in file

 



tbone587
User

May 29, 2011, 9:06 PM

Post #1 of 3 (515 views)
Trouble Matching numeric value in file Can't Post

I am having an issue matching numeric values within a file that was opened. I am trying to match the number 67 against the value ($LastOctet)in the line below:
"67 IN PTR tms339.tristan.net." I cant seem to get it to match the number. I have been using:


Code
if ($line =~ m/$LastOctet/) 
{
print "$LastOctet has alread been found in PTR record\n";
}


I am not getting anything back, $LastOctet equals 67 at that point, so it should match the value of $line within a file.


rovf
Veteran

May 30, 2011, 5:09 AM

Post #2 of 3 (501 views)
Re: [tbone587] Trouble Matching numeric value in file [In reply to] Can't Post

$ perl -lwe 'use strict; my $line="67 IN PTR tms339.tristan.net"; my $LastOctet
=67; $line =~ m/$LastOctet/ && print "$LastOctet has alread been found in PTR record"'
67 has alread been found in PTR record

Corollary: One of the following assertions holds:

(1) $LastOctet is not 67 in your case

(2) $line does not contain 67 in your case

(3) Your Perl installation is broken

(4) A miracle occured (please report to the Vatican)

Side note: While it is neither wrong nor bad to use a regexp here, you might consider alternatively using "index" as a safer replacement to your current code.


Zhris
Enthusiast

May 30, 2011, 5:13 AM

Post #3 of 3 (500 views)
Re: [tbone587] Trouble Matching numeric value in file [In reply to] Can't Post

Just to add. Check that the number 67 doesn't have any whitespace surrounding it e.g.

print ">$LastOctet<";
#>67< not > 67< etc

Chris


(This post was edited by Zhris on May 30, 2011, 5:14 AM)

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives