Scripts: Perl :: File System :: Library Article #4
Developer's Section
Write data to a file using PERL By: Erobo Team Member
|
Hire a Developer for Related Work / Installation | $55 hr
|
|
Rating: | Rate It:
|
Average Votes: (3143)
|
Favorites:
|
|
|
|
Learn how to use the open() method to write to a file using PERL.
Use the following code to write data to a file using PERL:
| Code Snippet 1 |
|
|
#!/usr/bin/perl -w
#Using Perl Error Handling Exceptions
#(Output errors before executing the script)
qw(:standard);
use CGI::Carp qw(fatalsToBrowser);
#end error handling
#print "Content-type: text/html\n\n";
# process POST information
read(stdin, $input_line, $ENV{CONTENT_LENGTH});
$input_line =~ tr/+/ /;
@fields = split(/\&/,$input_line);
foreach $i (0 .. $#fields) {
($name,$value) = split(/=/,$fields[$i]);
$name =~ s/%(..)/pack("c",hex($1))/ge;
$value =~ s/%(..)/pack("c",hex($1))/ge;
$input{$name} = $value;
}
#USE >> FOR APPEND, > TO WRITE, AND < TO READ
open (MYFILE, ">>data.txt") || die "\n Cannot open \n";
print MYFILE "$input{'empID'}\t";
print MYFILE "$input{'firstname'}\t";
print MYFILE "$input{'lastname'}\t";
#Create a timestamp and write it to the file
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
$year += 1900;
$mon++;
print MYFILE "$mon/$mday/$year\n";
close MYFILE;
|
|
|
See other Scripts in File System |
Submit Your Scripts: |
If you would like to have your Perl scripts published in this section please fill out the form below: |