473,396 Members | 1,683 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

printing the output of a program in another file

hello all,
i am new to programming,i wrote a program for extracting name of the contents in a directory.i got the output in a dos window.now,i wanted to save this output in another file.while i tried this,my output file contained the contents in a straight line,rather than printing it in line sequence.my program is here

Expand|Select|Wrap|Line Numbers
  1. opendir DIR, "D:\dir.";   
  2. open DIRO,'+>>out.txt';
  3. while ( $filename = readdir(DIR) ) 
  4.     {
  5.  print $filename , "\n";
  6. writeline DIRO , $filename , "\n";
  7.     }
  8. close DIRO;
  9. closedir DIR;
  10.  
Sep 17 '07 #1
1 1337
numberwhun
3,509 Expert Mod 2GB
hello all,
i am new to programming,i wrote a program for extracting name of the contents in a directory.i got the output in a dos window.now,i wanted to save this output in another file.while i tried this,my output file contained the contents in a straight line,rather than printing it in line sequence.my program is here

Expand|Select|Wrap|Line Numbers
  1. opendir DIR, "D:\dir.";   
  2. open DIRO,'+>>out.txt';
  3. while ( $filename = readdir(DIR) ) 
  4.     {
  5.  print $filename , "\n";
  6. writeline DIRO , $filename , "\n";
  7.     }
  8. close DIRO;
  9. closedir DIR;
  10.  
Welcome to TSDN and to Perl coding!

Well, unless you wrote a function named "writeline" and are using it here, there is not a function by that name that I know of. You will want to use print in place of your writeline statement like so:

Expand|Select|Wrap|Line Numbers
  1. print DIRO ($filename , "\n");
  2.  
Also, you don't need the "+" in the open statement. The >> will do an append out to the file mentioned.

Another way that you can go about getting a directory listing is to use the File::Util module from CPAN.

Regards,

Jeff
Sep 17 '07 #2

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

Similar topics

16
by: cyranoVR | last post by:
This is the approach I used to automate printing of Microsoft Access reports to PDF format i.e. unattended and without annoying "Save As..." dialogs, and - more importantly - without having to use...
4
by: Rob T | last post by:
I have a small VB program that has a printing module...very simple....and works great. However, If I try to print to a generic printer, I get the following error: "The data area passed to a...
1
by: al jones | last post by:
I'll try again as I'm obvioulsy standing in the middle of the forest and not seeing the trees ... I didn't think I was to old to learn new trick, but this has just about convinced me otherwise. I...
6
by: VJ | last post by:
I am able to print to File, which I am doing fine in our Program now. I want to be able to take this file and Print to a printer. Vijay
12
by: Alex Clark | last post by:
Greetings, (.NET 2.0, WinXP Pro/Server 2003, IE6 with latest service packs). I've decided to take advantage of the layout characteristics of HTML documents to simplify my printing tasks, but...
0
by: ryanf | last post by:
Hello, I need some help with printing pdf files through php. I have a script that will create many pdf files but I want them printed. I found this program to print pdf from the command line from...
6
by: sathyashrayan | last post by:
Dear group, Following is a exercise from a book called "Oreilly's practical C programming". I just wanted to do a couple of C programming exercise. I do have K and R book, but let me try some...
3
by: jonathan184 | last post by:
script is printing output correct but not the actual output. Basically what the script is doing it taking a 1 flat file then it is splits the file into smaller files in 1000 record increments ...
8
by: Neo Geshel | last post by:
Greetings. BACKGROUND: My sites are pure XHTML 1.1 with CSS 2.1 for markup. My pages are delivered as application/xhtml+xml for all non-MS web clients, and as text/xml for all MS web...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.