1MemHandle(3)          User Contributed Perl Documentation         MemHandle(3)
2
3
4

NAME

6       MemHandle - supply memory-based FILEHANDLE methods
7
8       DEPRECATED - Please use IO::Scalar from CPAN package IO::stringy
9       instead!
10

SYNOPSIS

12           use MemHandle;
13           use IO::Seekable;
14
15           my $mh = new MemHandle;
16           print $mh "foo\n";
17           $mh->print( "bar\n" );
18           printf $mh "This is a number: %d\n", 10;
19           $mh->printf( "a string: \"%s\"\n", "all strings come to those who wait" );
20
21           my $len = $mh->tell();  # Use $mh->tell();
22                                   # tell( $mh ) will NOT work!
23           $mh->seek(0, SEEK_SET); # Use $mh->seek($where, $whence)
24                                   # seek($mh, $where, $whence)
25                                   # will NOT work!
26
27           my $memory = $mh->mem();
28
29           Here's the real meat:
30
31           my $mh = new MemHandle;
32           my $old = select( $mh );
33           .
34           .
35           .
36           print "foo bar\n";
37           print "baz\n";
38           &MyPrintSub();
39           select( $old );
40
41           print "here it all is: ", $mh->mem(), "\n";
42

DESCRIPTION

44       Generates inherits from "IO::Handle" and "IO::Seekable". It provides an
45       interface to the file routines which uses memory instead.  See perldoc
46       IO::Handle, and perldoc IO::Seekable as well as perlfunc for more
47       detailed descriptions of the provided built-in functions:
48
49           print
50           printf
51           readline
52           sysread
53           syswrite
54           getc
55           gets
56
57       The following functions are provided, but tie doesn't allow them to be
58       tied to the built in functions.  They should be used by calling the
59       appropriate method on the MemHandle object.
60
61           seek
62           tell
63
64       call them like this:
65
66           my $mh = new MemHandle();
67           .
68           .
69           .
70           my $pos = $mh->tell();
71           $mh->seek( 0, SEEK_SET );
72

CONSTRUCTOR

74       new( [mem] )
75           Creates a "MemHandle", which is a reference to a newly created
76           symbol (see the "Symbol" package).  It then ties the FILEHANDLE to
77           "MemHandle::Tie" (see "Tying FileHandles" in perltie).  Tied
78           methods in "MemHandle::Tie" translate file operations into
79           reads/writes into a string, which can be accessed by calling
80           "MemHandle::mem".
81

METHODS

83       seek( POS, WHENCE )
84           Sets the read/write position to WHENCE + POS.  WHENCE is one of the
85           constants which are available from IO::Seekable or POSIX:
86
87               SEEK_SET # absolute position from the beginning.
88               SEEK_CUR # offset from the current location.
89               SEEK_END # from the end (POS can be negative).
90
91       tell()
92           Returns the current position of the mem-file, similar to the way
93           tell would.  (See perlfunc).
94
95       mem( [mem] )
96           gets or sets the memory.  If called with a parameter, it copies it
97           to the memory and sets the position to be immediately after (so if
98           you write more to it, you append the string).  Returns the current
99           value of memory.
100

NOTES

102       I don't have much time to contribute to this.  If you'd like to
103       contribute, please fork https://github.com/scr/cpan and send me a pull
104       request.
105

AUTHOR

107       "Sheridan C. Rawlins" <scr14@cornell.edu>
108

SEE ALSO

110       perl.  perlfunc.  "Tying FileHandles" in perltie.  perldoc IO::Handle.
111       perldoc IO::Seekable.  perldoc Symbol.
112
113
114
115perl v5.30.1                      2020-01-30                      MemHandle(3)
Impressum