George Feinman
George Feinman

Reputation: 1

how to hide unnecessary html tags in perl cgi when running from command line?

I'm using perl version 5.18. I don't have a provision to upgrade perl to a newer version. When I pass the CGI query parameters from the command line, the script runs and works perfectly but it shows unnecessary HTML tags and other things (<!DOCTYPE html PUBLIC...), which I want to hide from terminals. Those are necessary to execute the script from a browser. So, without affecting the functionality of cgi when it runs from the browser, is there any easy way to get only necessary outputs when running from command line/ terminal?

Upvotes: 0

Views: 78

Answers (1)

Dave Cross
Dave Cross

Reputation: 69314

The best approach here is to separate the data extraction from the presentation of the extracted data.

I would move the data extraction code into a module. You can then call that module from your CGI program and then wrap it in the appropriate layer of HTML.

You can then write a command-line version of your program that uses the same module to extract the correct data but which then wraps it in whatever text you want to use to display the data on the console.

Adding unwanted presentation layers (like your current HTML) is never a good idea. Best to rewrite from scratch to give what you want.

(If you're in a real rush though, there's one other approach that I might consider. Write a screen-scraper that scrapes your HTML page and extracts the data from that.)

Upvotes: 1

Related Questions