IO::InSitu 0.0.2
Sponsored Links
IO::InSitu 0.0.2 Ranking & Summary
File size:
0.006 MB
Platform:
Any Platform
License:
Perl Artistic License
Price:
Downloads:
1013
Date added:
2007-01-16
Publisher:
Damian Conway
IO::InSitu 0.0.2 description
IO::InSitu is a Perl module to avoid clobbering files opened for both input and output.
SYNOPSIS
use IO::InSitu;
my ($in, $out) = open_rw($infile_name, $outfile_name);
for my $line (<$in>) {
$line =~ s/foo/bar/g;
print {$out} $line;
}
When users want to do in-situ processing on a file, they often specify it as both the input and output file:
> myapp -i sample_data -o sample_data -op=normalize
But, if the -i and -o flags are processed independently, the program will usually open the file for input, open it again for output (at which point the file will be truncated to zero length), and then attempt to read in the first line of the now-empty file:
# Open both filehandles...
use Fatal qw( open );
open my $src, <, $source_file;
open my $dest, >, $destination_file;
# Read, process, and output data, line-by-line...
while (my $line = < $src >) {
print {$dest} transform($line);
}
Not only does this not perform the requested transformation on the file, it also destroys the original data. Fortunately, this problem is extremely easy to avoid: just make sure that you unlink the output file before you open it:
# Open both filehandles...
use Fatal qw( open );
open my $src, <, $source_file;
unlink $destination_file;
open my $dest, >, $destination_file;
# Read, process, and output data, line-by-line...
while (my $line = <$src>) {
print {$dest} transform($line);
}
If the input and output files are different, unlinking the output file merely removes a file that was about to be rewritten anyway. Then the second open simply recreates the output file, ready for writing.
If the two filenames actually refer to a single in-situ file, unlinking the output filename removes that filename from its directory, but doesnt remove the file itself from the filesystem. The file is already open through the filehandle in $input, so the filesystem will preserve the unlinked file until that input filehandle is closed. The second open then creates a new version of the in-situ file, ready for writing.
The only limitation of this technique is that it changes the inode of any in-situ file . That can be a problem if the file has any hard-linked aliases, or if other applications are identifying the file by its inode number. If either of those situations is possible, you can preserve the in-situ files inode by using the open_rw() subroutine that is exported from this module:
# Open both filehandles...
use IO::InSitu;
my ($src, $dest) = open_rw($source_file, $destination_file);
# Read, process, and output data, line-by-line...
while (my $line = <$src>) {
print {$dest} transform($line);
}
SYNOPSIS
use IO::InSitu;
my ($in, $out) = open_rw($infile_name, $outfile_name);
for my $line (<$in>) {
$line =~ s/foo/bar/g;
print {$out} $line;
}
When users want to do in-situ processing on a file, they often specify it as both the input and output file:
> myapp -i sample_data -o sample_data -op=normalize
But, if the -i and -o flags are processed independently, the program will usually open the file for input, open it again for output (at which point the file will be truncated to zero length), and then attempt to read in the first line of the now-empty file:
# Open both filehandles...
use Fatal qw( open );
open my $src, <, $source_file;
open my $dest, >, $destination_file;
# Read, process, and output data, line-by-line...
while (my $line = < $src >) {
print {$dest} transform($line);
}
Not only does this not perform the requested transformation on the file, it also destroys the original data. Fortunately, this problem is extremely easy to avoid: just make sure that you unlink the output file before you open it:
# Open both filehandles...
use Fatal qw( open );
open my $src, <, $source_file;
unlink $destination_file;
open my $dest, >, $destination_file;
# Read, process, and output data, line-by-line...
while (my $line = <$src>) {
print {$dest} transform($line);
}
If the input and output files are different, unlinking the output file merely removes a file that was about to be rewritten anyway. Then the second open simply recreates the output file, ready for writing.
If the two filenames actually refer to a single in-situ file, unlinking the output filename removes that filename from its directory, but doesnt remove the file itself from the filesystem. The file is already open through the filehandle in $input, so the filesystem will preserve the unlinked file until that input filehandle is closed. The second open then creates a new version of the in-situ file, ready for writing.
The only limitation of this technique is that it changes the inode of any in-situ file . That can be a problem if the file has any hard-linked aliases, or if other applications are identifying the file by its inode number. If either of those situations is possible, you can preserve the in-situ files inode by using the open_rw() subroutine that is exported from this module:
# Open both filehandles...
use IO::InSitu;
my ($src, $dest) = open_rw($source_file, $destination_file);
# Read, process, and output data, line-by-line...
while (my $line = <$src>) {
print {$dest} transform($line);
}
IO::InSitu 0.0.2 Screenshot
IO::InSitu 0.0.2 Keywords
IO
InSitu
InSitu 0.0.2
Input and output
to avoid
Perl module
For Both
file
open
output
line
input
files
IO::InSitu
IOInSitu
IO::InSitu 0.0.2
Bookmark IO::InSitu 0.0.2
IO::InSitu 0.0.2 Copyright
WareSeeker periodically updates pricing and software information of IO::InSitu 0.0.2 full version from the publisher, so some information may be slightly out-of-date. You should confirm all information before relying on it. Software piracy is theft, Using crack, password, serial numbers, registration codes, key generators is illegal and prevent future development of IO::InSitu 0.0.2 Edition. Download links are directly from our publisher sites, torrent files or links from rapidshare.com, yousendit.com or megaupload.com are not allowed
Featured Software
Want to place your software product here?
Please contact us for consideration.
Contact WareSeeker.com
Related Information
input and output devices
computer input and output devices
input output
wav files
filesharing
input and output device
input and output process
rar files
computer input and output
midi files
input and output computer devices
pdf files
file sharing
input and output device in a computer
zip files
input and output of computer
what is input and output
input and output devices of the computer
Related Software
IO::Busy is a Perl module to intercept terminal input while something else is happening. Free Download
KABC Client is a command line tool that provides access to the KDE address book. Free Download
Nanoserv is a sockets daemon toolkit for PHP 5.1+. Free Download
Movic project is a front-end for ffmpeg which converts video files to the formats supported by mobile devices. Free Download
Dialog is a Perl interface to dialog(3). Free Download
make utilities is a set of tools for use building C/C++ programs. Free Download
Videotrans is a set of scripts that convert a movie file in any format that mplayer understands to a DVD-compatible VOB file. Free Download
Sarien project is a Sierra AGI interpreter for games like Kings Quest and Space Quest. Free Download
Latest Software
Popular Software
Favourite Software