home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / share / doc / libhtml-parser-perl / examples / htextsub < prev    next >
Encoding:
Text File  |  2006-06-19  |  627 b   |  27 lines

  1. #!/usr/bin/perl -w
  2.  
  3. # Shows how to edit text in an HTML document.
  4.  
  5. use strict;
  6. my $code = shift || usage();
  7. $code = 'sub edit_print { local $_ = shift; ' . $code . '; print }';
  8. #print $code;
  9. eval $code;
  10. die $@ if $@;
  11.  
  12. use HTML::Parser 3.05;
  13. my $p = HTML::Parser->new(unbroken_text => 1,
  14.               default_h => [ sub { print @_; }, "text" ],
  15.                       text_h    => [ \&edit_print,      "text" ],
  16.                      );
  17.  
  18. my $file = shift || usage();
  19. $p->parse_file($file) || die "Can't open file $file: $!\n";
  20.  
  21. sub usage
  22. {
  23.     my $progname = $0;
  24.     $progname =~ s,^.*/,,;
  25.     die "Usage: $progname <perlexpr> <filename>\n";
  26. }
  27.