spillin_dylan
March 7th, 2011, 05:38 PM
I am writing a Perl script to try and find my external IP address. I have parsed a HTML page down to one line containing the IP address, along with some text. This line of text is saved within a variable. I am having problems getting the numbers out of this variable using regex. Here is what I have:
$ipaddr = `wget --quiet --tries=3 -O - http://checkmyip.com/ | grep id=\"ip\"` ; # Get the IP address, and put it in a variable.
$_ = $ipaddr;
/.*(\d.*\d).*$/;
print $1 . "\n";
exit 0;
I think that the \d should match the first and last digits in the variable (greedy matching) and the brackets should put it into variable $1. But when I try this out I get:
Use of uninitialized value $1 in string at /home/spillin/bin/newipnotify.pl line 95.
Sorry if I'm missing something obvious here, but I'm still learning....
Thanks!
-spillin
$ipaddr = `wget --quiet --tries=3 -O - http://checkmyip.com/ | grep id=\"ip\"` ; # Get the IP address, and put it in a variable.
$_ = $ipaddr;
/.*(\d.*\d).*$/;
print $1 . "\n";
exit 0;
I think that the \d should match the first and last digits in the variable (greedy matching) and the brackets should put it into variable $1. But when I try this out I get:
Use of uninitialized value $1 in string at /home/spillin/bin/newipnotify.pl line 95.
Sorry if I'm missing something obvious here, but I'm still learning....
Thanks!
-spillin