Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5976927
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:17:51+00:00 2026-05-22T21:17:51+00:00

It involves rewriting .htm to .txt (output file) then using a parser (stanford grammar

  • 0

It involves rewriting .htm to .txt (output file)

then using a parser (stanford grammar parser) (output file)

for all the files in a directory.

MY QUESTION: I would like to get all the files in the directory, without doing it manually, and find a way to run the parser, without having to type it into the Terminal for each file.

Here is my code:

#!/usr/bin/perl
use strict;
use warnings;
use HTML::FormatText;
use HTML::TreeBuilder;

my $tree = HTML::TreeBuilder->new->parse_file("chpt15Intro.htm");

use HTML::FormatText;

my $formatter = HTML::FormatText->new(leftmargin => 0, rightmargin => 1000);
   #print $formatter->format($tree); is replaced by push
push (my @files, $formatter->format($tree));
foreach my $files (@files) {
    $files =~ s/^\s+//mg;
    open MYFILE, ">ch15Intro.txt"; 
    select MYFILE; 
    print $files;
}

In the Terminal, after getting the html file converted, I write:

script parsedch15Intro.txt ./lexparser.csh ch15Intro.txt

to save the output of the parser. This step still needs automation.

I’m a beginner so thanks for any advice.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T21:17:52+00:00Added an answer on May 22, 2026 at 9:17 pm

    I take it from your question that what you want to do is to apply this script to all the (html-) files in a certain folder, and output text versions of them.

    So a simple solution is to simply replace the hardcoded file names with variables, and loop the script around the @ARGV, e.g. the arguments to the script, like so:

    for my $file (@ARGV) {
        next unless ($file =~ /^(.+).html*$/i);
        my $outfile = $1 . ".txt";
        my $tree = HTML::TreeBuilder->new;
        $tree->parse_file($file); # credit to Phil for this one
        my $formatter = HTML::FormatText->new(leftmargin => 0, rightmargin => 1000);
        foreach my $files ($formatter->format($tree)) {
            $files =~ s/^\s+//mg;
            open my $fh, '>', $outfile or die $!; 
            print $fh $files;
        }
    }
    

    As you see, I cleaned up some of it. Use like so:

    > script.pl *.htm
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My current project involves deploying an upgraded .exe file that runs as a Windows
Currently my method involves creating a context processor which is then included sitewide. However,
My particular scenario involves doing some text transformation using regular expressions within a private
My question involves a simple game that 2-4 people can play. This is a
My user experience involves users submitting a form before they've authenticated (using omniauth). I
My project that involves antenna design, in which Python generates the .nec file that
My program involves a number of JAVA threads calling a KornShell (ksh) script file
My team's current project involves re-writing retrieval libraries in JavaScript. We are basically looking
My production environment involves a pair of IIS 6 web servers, one running legacy
My WCF service involves the sending of a dataset (in csv format) data between

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.