Solved

RETRIEVING TEXT FILE CONTENT

Posted on 2001-07-15
2
149 Views
Last Modified: 2013-12-25
i have a lot of html files.i want a perl script that will loop through each file and store the title and description values in two different arrays.

please find below the template of the html pages.

<html>
<head>
<title> i am the title</title>
<description> i describe this html page</description>
</head>
<body>
</body>
</html>

0
Comment
Question by:augblay
2 Comments
 
LVL 2

Accepted Solution

by:
psogaa earned 200 total points
ID: 6285949
use the perl script below, give as argument the target directory.

****************************************************

$targetDir = $ARGV[0];
opendir( DIR, $targetDir );
@files = grep( /\.html?$/,readdir( DIR )) or die "can't open dir: $!";
closedir( DIR );
@titles;
@descriptions;
foreach $file (@files){
  open( FILE, "$targetDir/$file" ) or die "can't open file: $!";  
  {
    undef( $/ );
    $fileContent = <FILE>;
  }  
  close FILE;
  $fileContent =~ /<title>(.*?)<\/title>.*?<description>(.*?)<\/description>/si;
  push( @titles, $1 );
  push( @descriptions, $2);    
}
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6419722
Open today, need more?
Moondancer
Community Support Moderator @ Experts Exchange
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this tutorial I will focus on how to use WhizBase as a tool for sending ICQ messages to ICQ. Here I will use a new technology in WhizBase, published in WhizBase 5.1 version. In this tutorial I will use 3 files, pager.wbsp for the processing, e…
This tutorial will discuss the log-in process using WhizBase. In this article I assume you already know HTML. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you might look at some of my other articles abo…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now