473,503 Members | 1,646 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Pipe to list all readable text files

1 New Member
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:

#!/usr/bin/perl
$directory="./";
opendir(FH, $directory) || die "Not readable \n";
@allfiles= readdir(FH);
closedir(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
1 2930
KevinADC
4,059 Recognized Expert Specialist
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. }
  5.  
May 20 '09 #2

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

Similar topics

0
5816
by: Bernhard Kuemel | last post by:
Hi! I want to read/write commands and program input to/from /bin/bash several times before I close the stdin pipe. However, reading from cat hangs unless I first close the stdin pipe. <?php...
0
3942
by: Chris Jankowski | last post by:
I am trying to print an image file to a network printer and getting the following error. This is a Windows based system, using a network printer. Any ideas. Error Message: cannot print image...
3
6492
by: chudson007 | last post by:
Can somebody help me with a delimiter problem I have. I have several PIPE (|) delimted text files which I need to import to SQL. With one of the files I keep encountering the following error;...
2
1659
by: Steve R. Hastings | last post by:
While studying iterators and generator expressions, I started wishing I had some tools for processing the values. I wanted to be able to chain together a set of functions, sort of like the...
0
1663
by: Masa Ito | last post by:
I have pipe delimited (and comma/tab) files that I read with JET using a schema file. Occasionally a field has multiple quotes (") inside a single field - which chokes the line (the rest of the...
6
6186
by: placid | last post by:
Hi all, I have been looking into non-blocking read (readline) operations on PIPES on windows XP and there seems to be no way of doing this. Ive read that you could use a Thread to read from the...
7
1749
by: SimonPalmer | last post by:
Hi, I am looking for a way to convert a List of floating point numbers to and from text. I am embedding it in an XML document and am looking for a neat way to serialise and de-serialise a list...
3
8659
by: Jeremy Sanders | last post by:
Hi - I have some code which works under linux. It starts a remote python process using subprocess and communicates to it via a pipe created by os.pipe. As far as I understand, child processes...
0
7198
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7072
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7271
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6979
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7449
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4666
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3160
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
373
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.