
Untitled
By: a guest on
Apr 15th, 2012 | syntax:
None | size: 0.54 KB | hits: 7 | expires: Never
#!/usr/bin/perl
BEGIN {
use strict;
use warnings;
use URI;
use Socket;
use Getopt::Std;
our %opts;
getopts('nqi', \%opts);
}
while(<STDIN>) {
my $uri = eval { URI->new($_); };
if ($@) {
warn $@ if !$opts{q};
next;
}
foreach( @ARGV ) {
if ( $uri->can($_) ) {
if ( $_ eq 'host' && $opts{i} ) {
my $h = $uri->host();
print inet_ntoa( scalar( gethostbyname( $h ) ) );
} else {
print $uri->$_();
}
print $opts{n}? "\n" : " ";
} else {
warn "No such method URI->$_\n"
unless $opts{q};
}
}
}