Home
 
 
Search:  
C C++ Perl PHP Python HTML ShellScripts
 
 
  Coding Books
  Tutorials
  Search Code
  Browse Code
  Link to Us
  Site News
  Contact Metalshell
 
 
 
  Submit Code   Statistics
 



Perl for System Administration    (ISBN: 1565926099)


 

 List Price: $34.95
 Our Price: $24.47
 Used Price: $8.90

 Release Date: 15 January, 2000
 Manufacturer: O'Reilly & Associates (Paperback)
 Sales Rank: 34,197

 Author: David N. Blank-Edelman









More Info

 Write File 2002-07-15 11:15:15
  perl 
Category: source:perl:files
Description: Write over top of a file or append to a file in perl.
Platform: unix/win
Author: detour
Viewed: 6767
Rating: 4.7/5 (44 votes)
If you have any questions about this piece of code or still need help, try posting your question on the forum.

 

Printable Version
writefile.pl
#!/usr/bin/perl
#
# writefile.pl by detour@metalshell.com
#
# Write output to a file.
#
# http://www.metalshell.com/

use strict;

# Open file to be overwritten using the single greater then char
open(OUTFILE, ">tmp.out");
print OUTFILE "This line will be the first line in tmp.out\n";
print OUTFILE "Any old data in tmp.out has been overwritten\n";
print OUTFILE "--------------------------------------------\n";
close(OUTFILE);

# Open file for append using the double greater then char's
open(OUTFILE, ">>tmp.out");
print OUTFILE "This line will be appended to tmp.out\n";
close(OUTFILE);

# Open the file to print out what is inside.
open(INFILE, "tmp.out");
while(<INFILE>) {
  print $_;
}
close(INFILE);
Rate this code:
(Not Helpful)  (Very Helpful) 

 
 
   Developer.*  
   Blue Parrots  
   Technipal  
   Defy Magazine  
   Code Project  
   Prog. Heaven  


Got Money?