CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Retrieving information from files

 



ab2388
New User

Nov 16, 2010, 9:53 AM

Post #1 of 2 (370 views)
Retrieving information from files Can't Post

Hi,

I have a list of .ksh files in a text file (txtfile.txt):

file1.ksh
file2.ksh
file3.ksh

The .ksh files contain paths of other files with the following extensions: .txt, .dat.

What I would like to do is parse through all the .ksh files contained in the text file (txtfile.txt) and retrieve the paths and filenames for all the files inside the .ksh files that have extensions .txt and .dat.

So far I have:


Code
# open file 
open(FILE, "kshfiles.txt") or die("Unable to open file");

# read file into an array
my @kshNames = <FILE>;

foreach (@kshNames) {
open(kshFile, $_);
...
}

# close file
close(FILE);


I guess I am not sure how to go about retrieving the paths and filenames of .txt and .dat files inside of the .ksh files. Any ideas?


Thanks!


rovf
Veteran

Nov 17, 2010, 2:02 AM

Post #2 of 2 (362 views)
Re: [ab2388] Retrieving information from files [In reply to] Can't Post

First of all:

(1) use strict; use warnings; is missing in your code.

(2) File handles should be all-upper-case or, better, lexical variables.

As for extracting your pathes, you would loop through the ksh file and fetch the pathes you are interested in with a suitable regular expression.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives