?
Solved

RETRIEVING TEXT FILE CONTENT

Posted on 2001-07-15
2
Medium Priority
?
155 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 2

Accepted Solution

by:
psogaa earned 800 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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

This tutorial will discuss fancy secure registration forms, with AJAX technology support. In this article I assume you already know HTML and some JS. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you mig…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses

777 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