#!/usr/bin/perl
use strict;
use Carp;
use Getopt::Std::Strict 'hvt:';
our $VERSION = sprintf "%d.%02d", q$Revision: 1.2 $ =~ /(\d+)/g;
$opt_h and print STDERR usage() and exit;
$opt_v and print $VERSION and exit;

sub usage {q{htmltag [OPTION]..
Grep stdin for tags.

   -h           help
   -t string    tag wanted

Try 'man htmltag' for more info.
}}


$opt_t or die('missing argument');


while(<>){ 
   my $line = $_;

   my $q=qr/['"]/;

   if ($line=~/(<$opt_t[^><]+>)/i){
      my $tag = $1;


      my @att;

      while ($tag=~/([a-z]+)\s*=\s*$q([^"']+)$q/ig){
         my($att, $val)=($1,$2);
         push @att, [$att,$val];
      }


      printf "%s\n", join(',', map { join('=',@$_) } @att);

   }


}

__END__

=pod

=head1 NAME

htmltag - grep out tag info from html stdin 

=head1 USAGE

htmltag [OPTION]..

   -v           version 
   -h           help
   -t string    tag wanted

=head2 USAGE EXAMPLES

   wget http://site.com -O - | htmltag -t meta | grep keywords

=head1 AUTHOR

Leo Charre leocharre at cpan dot org

=head1 LICENSE

This package is free software; you can redistribute it and/or modify it under the same terms as Perl itself, i.e., under the terms of the "Artistic License" or the "GNU General Public License".

=head1 DISCLAIMER

This package is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

See the "GNU General Public License" for more details.

=cut



