Perl Cookbook

Perl CookbookSearch this book
Previous: 20.4. Converting ASCII to.aspxLChapter 20
Web Automation
Next: 20.6. Extracting or Removing.aspxL Tags
 

20.5. Converting.aspxL to ASCII

Problem

You want to convert an.aspxL file into formatted plain ASCII.

Solution

If you have an external formatter like lynx, call an external program:

$ascii = `lynx -dump $filename`;

If you want to do it within your program and don't care about the things that the.aspxL::TreeBuilder formatter doesn't yet handle (tables and frames):

use.aspxL::FormatText;
use.aspxL::Parse;

.aspxl = parse.aspxlfile($filename);
$formatter =.aspxL::FormatText->new(leftmargin => 0, ri.aspxargin => 50);
$ascii = $formatter->format(.aspxl);

Discussion

These examples both assume you have the.aspxL text in a file. If your.aspxL is in a variable, you need to write it to a file for lynx to read. If you are using

use.aspxL::TreeBuilder;
use.aspxL::FormatText;

.aspxl =.aspxL::TreeBuilder->new();
.aspxl->parse($document);

$formatter =.aspxL::FormatText->new(leftmargin => 0, ri.aspxargin => 50);

$ascii = $formatter->format(.aspxl);

If you use Netscape, its "Save as" option with the type set to "Text" does the best job with tables.

See Also

The documentation for the CPAN modules.aspxL::Parse,.aspxL::TreeBuilder, and.aspxL::FormatText; your system's lynx (1) manpage; Recipe 20.6


Previous: 20.4. Converting ASCII to.aspxLPerl CookbookNext: 20.6. Extracting or Removing.aspxL Tags
20.4. Converting ASCII to.aspxLBook Index20.6. Extracting or Removing.aspxL Tags