By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,692 Members | 1,998 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,692 IT Pros & Developers. It's quick & easy.

Pipe to list all readable text files

P: 1
Hello All,

I am currently in a Perl programming class and our assignment was:

Create a filehandle with the open function that uses a pipe to list all the files in your current directory and will print only those files that are readable text files. Use the die function to quit if the open fails.

After several hours, i have completed a program that does find all of the readable files in the current directory however I could not figure out how to do so using the pipe command. Here is what i have so far:

opendir(FH, $directory) || die "Not readable \n";
@allfiles= readdir(FH);

foreach $file (@allfiles){
unless (($file eq ".") || ($file eq "..")){
print "$file \n" if -r $file;

I have been working on this code for a while now and any help would be greatly appreciated. Thank you!
May 19 '09 #1
Share this Question
Share on Google+
1 Reply

Expert 2.5K+
P: 4,059
If the point is to use a pipe open then you won't be using perls -r file test operator but whatever the operating system the script runs on has to check if a file is readable.:

Expand|Select|Wrap|Line Numbers
  1. open(PIPE, "| operating system commands here") or die "$!";
  2. while(<PIPE>){
  3.    print "$_\n";
  4. }
May 20 '09 #2

Post your reply

Sign in to post your reply or Sign up for a free account.