Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 15th, 2012  |  syntax: None  |  size: 0.54 KB  |  hits: 7  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #!/usr/bin/perl
  2.  
  3. BEGIN {
  4.         use strict;
  5.         use warnings;
  6.  
  7.         use URI;
  8.         use Socket;
  9.         use Getopt::Std;
  10.  
  11.         our %opts;
  12.  
  13.         getopts('nqi', \%opts);
  14. }
  15.  
  16. while(<STDIN>) {
  17.         my $uri = eval { URI->new($_); };
  18.        
  19.         if ($@) {
  20.                 warn $@ if !$opts{q};
  21.                 next;
  22.         }
  23.        
  24.         foreach( @ARGV ) {
  25.                 if ( $uri->can($_) ) {
  26.                         if ( $_ eq 'host' && $opts{i} ) {
  27.                                 my $h = $uri->host();
  28.                                 print inet_ntoa( scalar( gethostbyname( $h ) ) );
  29.                         } else {
  30.                                 print $uri->$_();
  31.                         }
  32.        
  33.                         print $opts{n}? "\n" : " ";
  34.                 } else {
  35.                         warn "No such method URI->$_\n"
  36.                                 unless $opts{q};
  37.                 }
  38.         }
  39. }