|
NAMEInline::Files::Virtual - Multiple virtual files in a single fileVERSIONThis document describes version 0.53 of Inline::Files::Virtual, released May 25, 2001.SYNOPSISuse Inline::Files::Virtual; # Load actual file, extracting virtual files that start with "^<VF>\n" @virtual_filenames = vf_load($actual_file, "^<VF>\n"); # Open one of the virtual files for reading open(FILE, $virtual_filenames[0]) or die; print while <FILE>; close(FILE); # Open one of the virtual files for appending open(FILE, ">> $virtual_filenames[1]") or die; print FILE "extra text"; printf FILE "%6.2", $number; close(FILE); # Actual file will be updated at this point WARNINGThis module is still experimental. Careless use of it will almost certainly cause the source code in files that use it to be overwritten. You are strongly advised to use the Inline::Files module instead.If you chose to use this module anyway, you thereby agree that the authors will b<under no circumstances> be responsible for any loss of data, code, time, money, or limbs, or for any other disadvantage incurred as a result of using Inline::Files. DESCRIPTIONThis module allows you to treat a single disk file as a collection of virtual files, which may then be individually opened for reading or writing. Virtual files which have been modified are written back to their actual disk at the end of the program's execution (or earlier if the "vf_save" subroutine is explicitly called).Each such virtual file is introduced by a start-of-virtual-file marker (SOVFM). This may be any sequence (or pattern) of characters that marks the beginning of the content of a virtual file. For example, the string "--" might be used: -- Contents of virtual file number 1 -- Contents of virtual file number 2 -- Contents of virtual file number 3 or the pattern "/##### \w+ #####/": ##### VF1 ##### Contents of virtual file number 1 ##### VF2 ##### Contents of virtual file number 2 ##### VF3 ##### Contents of virtual file number 3 Note that the SOVFM is not considered to be part of the file contents. InterfaceThe module exports the following methods:
The module also modifies the "open", "close", "print", "printf", "read", "getline", "getc", "seek", "tell", and "truncate" built-in functions so that they operate correctly on virtual files. As a special case, it is also possible to use the raw SOVFM as a virtual file name: use Inline::Files::Virtual; vf_load $filename, qr/__[A-Z]+__/; open FILE, "__MARKER__"; # and in the file that was vf_load-ed __MARKER__ file contents here However, this always opens the very first virtual file with that SOVFM, no matter how often it is called, or how many such markers appear in the file. Handling "implicit" virtual start-of-virtual-file markersSometimes an SOVFM is "implicit". That is, rather thanb being a separate marker for the start of a virtual file, it is the first part of the actual data of the virtual file. For example, consider the following XML file:<DATA> <DESC>This is data set 1</DESC> <DATUM/>datum 1 <DATUM/>datum 2 <DATUM/>datum 3 </DATA> <DATA> <DESC>This is data set 2</DESC> <DATUM/>datum 4 <DATUM/>datum 5 <DATUM/>datum 6 </DATA> Each of the "<DATA>...</DATA>" blocks could be treated as a separate virtual file by specifying: @datasets = vf_load("data.xml", '<DATA>'); But this would cause the individual virtual files to contain invalid XML, such as: <DESC>This is data set 1</DESC> <DATUM/>datum 1 <DATUM/>datum 2 <DATUM/>datum 3 </DATA> One can indicate that the nominated SOVFMs are also part of the virtual files' contents, by specifying the markers as a look-ahead pattern: @datasets = vf_load("data.xml", '(?=<DATA>)'); This causes "vf_load" to identify the sequence "<DATA>" as a start-of-virtual-file marker but not consume it, thereby leaving it as the initial sequence of the virtual file's content. DIAGNOSTICS
AUTHORDamian Conway (damian@conway.org)EVIL GENIUS WHO MADE HIM DO ITBrian Ingerson (INGY@cpan.org)COPYRIGHTCopyright (c) 2001. Damian Conway. All rights reserved.This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See http://www.perl.com/perl/misc/Artistic.html
Visit the GSP FreeBSD Man Page Interface. |