flyganji has asked for the wisdom of the Perl Monks concerning the following question:
Hi all, First time writing perl question here. Thank you all for help. I have an assignment to write a few lines of code that would match an IP address from $string and store it in a variable called $ip. $string = "My IP is 10.0.0.2" and the result should be $ip = "10.0.0.2" My trial code was
#!/usr/bin/perl $string = "My IP is 10.0.0.2"; if($string =~/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/{ $ip = $string; } print "$ip\n";
I know this will print out "My IP is 10.0.0.2" but I can't seem to make find a solution to print just IP = 10.0.0.2. thank you all again for any solution.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: print ip address from string using regex
by roboticus (Chancellor) on Oct 04, 2011 at 15:28 UTC | |
by flyganji (Initiate) on Oct 04, 2011 at 20:47 UTC | |
|
Re: print ip address from string using regex
by AR (Friar) on Oct 04, 2011 at 15:23 UTC | |
by Anonymous Monk on Aug 14, 2013 at 07:40 UTC |