Hi Experts,
I am new to perl. The following code works fine.
#!/opt/perl/bin/perl use strict; use warnings;
my $str="http://162.16.23.0"; if( $str =~ /(\d+)\.(\d+)\.(\d+)\.(\d+)/ ) { print "$1.$2.$3.$4"; }
But, How to simplify the following line & print the IP in the above code?.
$str =~ /(\d+)\.(\d+)\.(\d+)\.(\d+)/
if ($str =~ /^http:\/\/([^\/]+)/) { print $1,"\n"; }
Or numerous variations on the theme...
What do you really want ;-) ?
print substr($str, 7);
Or more to the point what do you really have, are you guaranteed that you will always have an 'http://' followed by a known valid IP address? Or do you have to worry about domain names, or non-valid IP addresses (999.999999.8888.33333 passes your test but isn't an IP)? IPs are notoriously hard for pulling out of a string that can contain arbitrary values... so what are your real cases?
http://danconia.org
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>