|vf_load $file, $SOVFM_pattern||
This subroutine is called to load an actual disk file containing one or
more virtual files. The first argument specifies the name of the file to
be loaded as a string. The second argument specifies a pattern (as
either a string or qr regex) that matches each start-of-virtual-file
marker within the file. For example, if the file
then you could load it as three virtual files with:
Note that, because the actual file is decomposed into virtual files using a split, it is vital that the pattern does not contain any capturing parentheses.
On success, vf_load returns a list of virtual filenames for the virtual files. Each virtual filename consists of the actual name of the file containing the virtual file, concatenated with the offset of the virtual files SOVFM within the actual file. For example, the above call to vf_load would return three virtual filenames:
When any of these virtual filenames is subsequently used in an open, the corresponding virtual file is opened.
This subroutine causes the virtual files belonging to the nominated
actual file (or files) to be written back to disk. If vf_save is
called without arguments, then all currently loaded virtual files are
saved to their respective actual files at that point.
vf_save is automatically called in an END block at the termination of any program using the module.
|vf_marker $virtual_filename||This subroutine returns the SOVFM that preceded the nominated virtual file.|
As a special case, it is also possible to use the raw SOVFM as a virtual file name:
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.
Sometimes 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 files content.
Could not vf_load %s The module could not open the specified disk file and read it in as a set of virtual files. Unable to complete vf_save The module could not open the specified disk file and write it out as a set of virtual files. A preceding warning may indicate which virtual file caused the problem. Virtual file not open for input An attempt was made to getline, getc, or read a virtual file that was opened for output only. (Warning only) Virtual file not open for output An attempt was made to print or printf a virtual file that was opened for input only. (Warning only)
Damian Conway (firstname.lastname@example.org)
Brian Ingerson (INGY@cpan.org)
Copyright (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.
|perl v5.20.3||INLINE::FILES::VIRTUAL (3)||2011-01-31|