perl map, while, regexp, trick (Simple PROJECT Count TAG code)

Filed under รวม code ทั้งมั่วเอง ทั้งจิ๊กชาวบ้านมา
Tagged as ,
my @tags = qw(a h1 h2 h3 h4 h5 h6 img link meta p title);
my %hash = map {lc($_) => 0} @tags;
my $tag_regexp = join ("|", @tags);
while ($line =~ /<(($tag_regexp)([^>]+)?)>/ig){
  my $regex = $1;
  if($regex =~/\s/){
    my ($tag, $option) = split(/\s/, lc($regex),2);
    print "TAG : $tag / Option ($option)\n";
  }else{
    print "TAG : $regex / Option (Null)\n";  
  }
}
Share and Enjoy:
  • Facebook
  • Twitter
  • del.icio.us
  • Digg
  • Google Bookmarks

Post a Comment

You must be logged in to post a comment.