Download Shareware and Freeware Software for Windows, Linux, Macintosh, PDA

line Home  |  About Us  |  Link To Us  |  FAQ  |  Contact

Serving Software Downloads in 976 Categories, Downloaded 29.612.781 Times

IO::InSitu 0.0.2

  Date Added: October 08, 2010  |  Visits: 1.100

IO::InSitu

Report Broken Link
Printer Friendly Version


Product Homepage
Download (70 downloads)



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); }.

Requirements: No special requirements
Platforms: Linux
Keyword: File Files Input Input And Output Insitu Io Ioinsitu Libraries Line Open Output Perl Module Programming
Users rating: 0/10

License: Freeware Size: 6.14 KB
USER REVIEWS
More Reviews or Write Review


IO::INSITU RELATED
Libraries  -  IO::Prompt 0.99.4
IO::Prompt is a Perl module to interactively prompt for user input. SYNOPSIS use IO::Prompt; while( prompt "next: " ) { print "You said $_n"; } By default, this module exports a single function prompt. It prompts the user to enter some...
14.34 KB  
Libraries  -  CAD::Drawing::IO::PostScript 0.03
CAD::Drawing::IO::PostScript is a Perl module with PostScript output methods. I would like this module to both load and save PostScript vector graphics, but I have not yet found a suitable PostScript parsing package. This module should be...
8.19 KB  
Modules  -  Rawlog 6.x-1.4
This module logs system events to a file, as a tiny and lightweight replacement option for watchdog (dblog for Drupal 6) module. It is intended for using in situations when the site is highly loaded and even disabling DB logging activity can...
10 KB  
Utilities  -  51View browser 1.1
51View is the the most convenient and powerful web browser for iPhone and iPod touch. The Features includes Tabs, Download, File Sharing, File Management, Save Page, and a lot more. TABS: Supports to open link in New...
2.8 MB  
Libraries  -  Bio::Phylo::IO 0.17 RC6
Bio::Phylo::IO Perl module contains input and output of phylogenetic data. SYNOPSIS use Bio::Phylo::IO; # parsing a tree from a newick string my $tree_string = (((A,B),C),D);; my $tree = Bio::Phylo::IO->parse( -string => $tree_string, #...
143.36 KB  
Libraries  -  IO::Busy 0.0.3
IO::Busy is a Perl module to intercept terminal input while something else is happening. SYNOPSIS use IO::Busy; my $fh = busy { non_interactive_stuff(); }; This module exports a single subroutine, named busy. That subroutine takes a...
4.1 KB  
Libraries  -  Bio::AlignIO::msf 1.4
Bio::AlignIO::msf is a Perl module with msf sequence input/output stream. SYNOPSIS Do not use this module directly. Use it via the Bio::AlignIO class. This object can transform Bio::Align::AlignI objects to and from msf flat file databases....
4.7 MB  
Libraries  -  IO::Multiplex 1.08
IO::Multiplex is a Perl module that can manage IO on many file handles. SYNOPSIS use IO::Multiplex; my $mux = new IO::Multiplex; $mux->add($fh1); $mux->add(*FH2); $mux->set_callback_object(...); $mux->listen($server_socket); $mux->loop;...
14.34 KB  
Libraries  -  File::Sort 1.01
File::Sort is a Perl module to sort a file or merge sort multiple files. SYNOPSIS use File::Sort qw(sort_file); sort_file({ I => [qw(file_1 file_2)], o => file_new, k => 5.3,5.5rn, -t => | }); sort_file(file1, file1.sorted); This...
32.77 KB  
Libraries  -  PDL::IO::Misc 2.4.3
PDL::IO::Misc is a Perl module with misc IO routines for PDL. rcols() Read ASCII whitespaced cols from a file into piddles and perl arrays (also see "rgrep()"). There are two calling conventions - the old version, where a pattern can be...
2.1 MB  
NEW DOWNLOADS IN PROGRAMMING, LIBRARIES
Programming  -  FLEX-db Digital Asset Manager 3.0.9
FLEX-db - an enterprise Digital Asset Manager (DAM). It ingests and links metadata with files, creates thumbnails, and processes files using business rules. FLEX-db has a JSP client, Java app server for file input and output and an EJB metadata...
21.57 MB  
Programming  -  Libicom 0.9.0
The libicom library is a character based dynamicly linked library for Linux. It is used to remotely control the Icom IC-R8500 wide band receiver via an RS232 link. All call and return parameters to the control functions are character string based....
20.48 KB  
Programming  -  dotdesktop 0.3
Dotdesktop library provides ability to parse desktop entry file and access the information in a convenient way. Desktop entry file format is defined by freedesktop.org, it is used to describe information about an application such as the name and...
327.68 KB  
Programming  -  Cedalion for Linux 0.2.6
Cedalion is a programming language that allows its users to add new abstractions and define (and use) internal DSLs. Its innovation is in the fact that it uses projectional editing to allow the new abstractions to have no syntactic limitations.
471.04 KB  
Programming  -  libyasl 0.2
Libyasl is a C++ class library to easily realize TCP/UDP/Multicast clientsand servers in IPv4 and IPv6 environments under GNU/Linux systems.
143.36 KB  
Libraries  -  wolfSSL 3.11.0
The wolfSSL embedded SSL/TLS library is a lightweight SSL library written in ANSI standard C and targeted for embedded and RTOS environments - primarily because of its small size, speed, and feature set. It is commonly used in standard operating...
2.73 MB  
Libraries  -  EuGTK 4.8.9
Makes it easy to develop good- looking, fast, cross-platform programs that run on Linux, OS X, and Windows. Euphoria is a very fast interpreted/compiled language with straight-forward syntax. EuGTK allows programming in a clean, object-oriented...
10.68 MB  
Libraries  -  Linux User Group Library Manager 1.0
The LUG Library Manager is a project to help Linux User Groups start their own library. A LUG library is helpful to the community at large because it increases access to information, and gives everyone the opportunity to become more knowledgeable.
5.35 KB  
Libraries  -  Module::MakefilePL::Parse 0.12
Module::MakefilePL::Parse is a Perl module to parse required modules from Makefile.PL. SYNOPSIS use Module::MakefilePL::Parse; open $fh, Makefile.PL; $parser = Module::MakefilePL::Parse->new( join("", ) ); $info = $parser->required;...
8.19 KB  
Libraries  -  sqlpp 0.06
sqlpp Perl package is a SQL preprocessor. sqlpp is a conventional cpp-alike preprocessor taught to understand SQL ( PgSQL, in particular) syntax specificities. In addition to the standard #define/#ifdef/#else/#endif cohort, provides also...
10.24 KB