{"id":7119,"date":"2022-12-20T19:35:32","date_gmt":"2022-12-20T22:35:32","guid":{"rendered":"http:\/\/lode.uno\/linux-man\/index.php\/2022\/12\/20\/ioscalar-man3\/"},"modified":"2022-12-20T19:35:32","modified_gmt":"2022-12-20T22:35:32","slug":"ioscalar-man3","status":"publish","type":"post","link":"https:\/\/lode.uno\/linux-man\/2022\/12\/20\/ioscalar-man3\/","title":{"rendered":"IO::Scalar (man3)"},"content":{"rendered":"<h1 align=\"center\">IO::Scalar<\/h1>\n<p> <a href=\"#NAME\">NAME<\/a><br \/> <a href=\"#SYNOPSIS\">SYNOPSIS<\/a><br \/> <a href=\"#DESCRIPTION\">DESCRIPTION<\/a><br \/> <a href=\"#PUBLIC INTERFACE\">PUBLIC INTERFACE<\/a><br \/> <a href=\"#AUTHOR\">AUTHOR<\/a><br \/> <a href=\"#CONTRIBUTORS\">CONTRIBUTORS<\/a><br \/> <a href=\"#COPYRIGHT &#038; LICENSE\">COPYRIGHT &#038; LICENSE<\/a> <\/p>\n<hr>\n<h2>NAME <a name=\"NAME\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">IO::Scalar \u2212 IO:: interface for reading\/writing a scalar<\/p>\n<h2>SYNOPSIS <a name=\"SYNOPSIS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Perform I\/O on strings, using the basic <small>OO<\/small> interface&#8230;<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">use 5.005; <br \/> use IO::Scalar; <br \/> $data = &#8220;My message:n&#8221;; <br \/> ### Open a handle on a string, and append to it: <br \/> $SH = new IO::Scalar $data; <br \/> $SH\u2212>print(&#8220;Hello&#8221;); <br \/> $SH\u2212>print(&#8220;, world!nBye now!n&#8221;); <br \/> print &#8220;The string is now: &#8220;, $data, &#8220;n&#8221;; <br \/> ### Open a handle on a string, read it line\u2212by\u2212line, then close it: <br \/> $SH = new IO::Scalar $data; <br \/> while (defined($_ = $SH\u2212>getline)) { <br \/> print &#8220;Got line: $_&#8221;; <br \/> } <br \/> $SH\u2212>close; <br \/> ### Open a handle on a string, and slurp in all the lines: <br \/> $SH = new IO::Scalar $data; <br \/> print &#8220;All lines:n&#8221;, $SH\u2212>getlines; <br \/> ### Get the current position (either of two ways): <br \/> $pos = $SH\u2212>getpos; <br \/> $offset = $SH\u2212>tell; <br \/> ### Set the current position (either of two ways): <br \/> $SH\u2212>setpos($pos); <br \/> $SH\u2212>seek($offset, 0); <br \/> ### Open an anonymous temporary scalar: <br \/> $SH = new IO::Scalar; <br \/> $SH\u2212>print(&#8220;Hi there!&#8221;); <br \/> print &#8220;I printed: &#8220;, ${$SH\u2212>sref}, &#8220;n&#8221;; ### get at value<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Don\u2019t like <small>OO<\/small> for your I\/O? No problem. Thanks to the magic of an invisible <b>tie()<\/b>, the following now works out of the box, just as it does with IO::Handle:<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">use 5.005; <br \/> use IO::Scalar; <br \/> $data = &#8220;My message:n&#8221;; <br \/> ### Open a handle on a string, and append to it: <br \/> $SH = new IO::Scalar $data; <br \/> print $SH &#8220;Hello&#8221;; <br \/> print $SH &#8220;, world!nBye now!n&#8221;; <br \/> print &#8220;The string is now: &#8220;, $data, &#8220;n&#8221;; <br \/> ### Open a handle on a string, read it line\u2212by\u2212line, then close it: <br \/> $SH = new IO::Scalar $data; <br \/> while (<$SH>) { <br \/> print &#8220;Got line: $_&#8221;; <br \/> } <br \/> close $SH; <br \/> ### Open a handle on a string, and slurp in all the lines: <br \/> $SH = new IO::Scalar $data; <br \/> print &#8220;All lines:n&#8221;, <$SH>; <br \/> ### Get the current position (WARNING: requires 5.6): <br \/> $offset = tell $SH; <br \/> ### Set the current position (WARNING: requires 5.6): <br \/> seek $SH, $offset, 0; <br \/> ### Open an anonymous temporary scalar: <br \/> $SH = new IO::Scalar; <br \/> print $SH &#8220;Hi there!&#8221;; <br \/> print &#8220;I printed: &#8220;, ${$SH\u2212>sref}, &#8220;n&#8221;; ### get at value<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">And for you folks with 1.x code out there: the old <b>tie()<\/b> style still works, though this is <i>unnecessary and deprecated<\/i>:<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">use IO::Scalar; <br \/> ### Writing to a scalar&#8230; <br \/> my $s; <br \/> tie *OUT, &#8216;IO::Scalar&#8217;, $s; <br \/> print OUT &#8220;line 1nline 2n&#8221;, &#8220;line 3n&#8221;; <br \/> print &#8220;String is now: $sn&#8221; <br \/> ### Reading and writing an anonymous scalar&#8230; <br \/> tie *OUT, &#8216;IO::Scalar&#8217;; <br \/> print OUT &#8220;line 1nline 2n&#8221;, &#8220;line 3n&#8221;; <br \/> tied(OUT)\u2212>seek(0,0); <br \/> while (<OUT>) { <br \/> print &#8220;Got line: &#8220;, $_; <br \/> }<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Stringification works, too!<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">my $SH = new IO::Scalar $data; <br \/> print $SH &#8220;Hello, &#8220;; <br \/> print $SH &#8220;world!&#8221;; <br \/> print &#8220;I printed: $SHn&#8221;;<\/p>\n<h2>DESCRIPTION <a name=\"DESCRIPTION\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">This class is part of the IO::Stringy distribution; see IO::Stringy for change log and general information.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The IO::Scalar class implements objects which behave just like IO::Handle (or FileHandle) objects, except that you may use them to write to (or read from) scalars. These handles are automatically &#8220;tiehandle&#8221;d (though please see &#8221; <small>WARNINGS&#8221;<\/small> for information relevant to your Perl version).<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Basically, this:<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">my $s; <br \/> $SH = new IO::Scalar $s; <br \/> $SH\u2212>print(&#8220;Hel&#8221;, &#8220;lo, &#8220;); ### OO style <br \/> $SH\u2212>print(&#8220;world!n&#8221;); ### ditto<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Or this:<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">my $s; <br \/> $SH = tie *OUT, &#8216;IO::Scalar&#8217;, $s; <br \/> print OUT &#8220;Hel&#8221;, &#8220;lo, &#8220;; ### non\u2212OO style <br \/> print OUT &#8220;world!n&#8221;; ### ditto<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Causes $s to be set to:<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">&#8220;Hello, world!n&#8221;<\/p>\n<h2>PUBLIC INTERFACE <a name=\"PUBLIC INTERFACE\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>Construction<\/b> <br \/> new [ <small>ARGS&#8230;<\/small> ]<\/p>\n<p style=\"margin-left:17%;\"><i>Class method.<\/i> Return a new, unattached scalar handle. If any arguments are given, they\u2019re sent to <b>open()<\/b>.<\/p>\n<p style=\"margin-left:11%;\">open [ <small>SCALARREF<\/small> ]<\/p>\n<p style=\"margin-left:17%;\"><i>Instance method.<\/i> Open the scalar handle on a new scalar, pointed to by <small>SCALARREF.<\/small> If no <small>SCALARREF<\/small> is given, a &#8220;private&#8221; scalar is created to hold the file data.<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">Returns the self object on success, undefined on error.<\/p>\n<p style=\"margin-left:11%;\">opened<\/p>\n<p style=\"margin-left:17%;\"><i>Instance method.<\/i> Is the scalar handle opened on something?<\/p>\n<p style=\"margin-left:11%;\">close<\/p>\n<p style=\"margin-left:17%;\"><i>Instance method.<\/i> Disassociate the scalar handle from its underlying scalar. Done automatically on destroy.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>Input and output<\/b> <br \/> flush<\/p>\n<p style=\"margin-left:17%;\"><i>Instance method.<\/i> No-op, provided for <small>OO<\/small> compatibility.<\/p>\n<p style=\"margin-left:11%;\">fileno<\/p>\n<p style=\"margin-left:17%;\"><i>Instance method.<\/i> No-op, returns undef<\/p>\n<p style=\"margin-left:11%;\">getc<\/p>\n<p style=\"margin-left:17%;\"><i>Instance method.<\/i> Return the next character, or undef if none remain.<\/p>\n<p style=\"margin-left:11%;\">getline<\/p>\n<p style=\"margin-left:17%;\"><i>Instance method.<\/i> Return the next line, or undef on end of string. Can safely be called in an array context. Currently, lines are delimited by &#8220;n&#8221;.<\/p>\n<p style=\"margin-left:11%;\">getlines<\/p>\n<p style=\"margin-left:17%;\"><i>Instance method.<\/i> Get all remaining lines. It will <b>croak()<\/b> if accidentally called in a scalar context.<\/p>\n<p style=\"margin-left:11%;\">print <small>ARGS&#8230;<\/small><\/p>\n<p style=\"margin-left:17%;\"><i>Instance method.<\/i> Print <small>ARGS<\/small> to the underlying scalar.<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><b>Warning:<\/b> this continues to always cause a seek to the end of the string, but if you perform <b>seek()<\/b>s and <b>tell()<\/b>s, it is still safer to explicitly seek-to-end before subsequent <b>print()<\/b>s.<\/p>\n<p style=\"margin-left:11%;\">read <small>BUF, NBYTES,<\/small> [ <small>OFFSET<\/small> ]<\/p>\n<p style=\"margin-left:17%;\"><i>Instance method.<\/i> Read some bytes from the scalar. Returns the number of bytes actually read, 0 on end-of-file, undef on error.<\/p>\n<p style=\"margin-left:11%;\">write <small>BUF, NBYTES,<\/small> [ <small>OFFSET<\/small> ]<\/p>\n<p style=\"margin-left:17%;\"><i>Instance method.<\/i> Write some bytes to the scalar.<\/p>\n<p style=\"margin-left:11%;\">sysread <small>BUF, LEN,<\/small> [ <small>OFFSET<\/small> ]<\/p>\n<p style=\"margin-left:17%;\"><i>Instance method.<\/i> Read some bytes from the scalar. Returns the number of bytes actually read, 0 on end-of-file, undef on error.<\/p>\n<p style=\"margin-left:11%;\">syswrite <small>BUF, NBYTES,<\/small> [ <small>OFFSET<\/small> ]<\/p>\n<p style=\"margin-left:17%;\"><i>Instance method.<\/i> Write some bytes to the scalar.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>Seeking\/telling and other attributes<\/b> <br \/> autoflush<\/p>\n<p style=\"margin-left:17%;\"><i>Instance method.<\/i> No-op, provided for <small>OO<\/small> compatibility.<\/p>\n<p style=\"margin-left:11%;\">binmode<\/p>\n<p style=\"margin-left:17%;\"><i>Instance method.<\/i> No-op, provided for <small>OO<\/small> compatibility.<\/p>\n<p style=\"margin-left:11%;\">clearerr<\/p>\n<p style=\"margin-left:17%;\"><i>Instance method.<\/i> Clear the error and <small>EOF<\/small> flags. A no-op.<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"4%\">\n<p>eof<\/p>\n<\/td>\n<td width=\"2%\"><\/td>\n<td width=\"61%\">\n<p><i>Instance method.<\/i> Are we at end of file?<\/p>\n<\/td>\n<td width=\"22%\"> <\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:11%;\">seek <small>OFFSET, WHENCE<\/small><\/p>\n<p style=\"margin-left:17%;\"><i>Instance method.<\/i> Seek to a given position in the stream.<\/p>\n<p style=\"margin-left:11%;\">sysseek <small>OFFSET, WHENCE<\/small><\/p>\n<p style=\"margin-left:17%;\"><i>Instance method.<\/i> Identical to &#8220;seek OFFSET, WHENCE&#8221;, <i>q.v.<\/i><\/p>\n<p style=\"margin-left:11%;\">tell<\/p>\n<p style=\"margin-left:17%;\"><i>Instance method.<\/i> Return the current position in the stream, as a numeric offset.<\/p>\n<p style=\"margin-left:11%;\">setpos <small>POS<\/small><\/p>\n<p style=\"margin-left:17%;\"><i>Instance method.<\/i> Set the current position, using the opaque value returned by &#8220;getpos()&#8221;.<\/p>\n<p style=\"margin-left:11%;\">getpos<\/p>\n<p style=\"margin-left:17%;\"><i>Instance method.<\/i> Return the current position in the string, as an opaque object.<\/p>\n<p style=\"margin-left:11%;\">sref<\/p>\n<p style=\"margin-left:17%;\"><i>Instance method.<\/i> Return a reference to the underlying scalar.<\/p>\n<h2>AUTHOR <a name=\"AUTHOR\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Eryq (<i>eryq@zeegee.com<\/i>). President, ZeeGee Software Inc (<i>http:\/\/www.zeegee.com<\/i>).<\/p>\n<h2>CONTRIBUTORS <a name=\"CONTRIBUTORS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Dianne Skoll (<i>dfs@roaringpenguin.com<\/i>).<\/p>\n<h2>COPYRIGHT &#038; LICENSE <a name=\"COPYRIGHT &#038; LICENSE\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Copyright (c) 1997 Erik (Eryq) Dorfman, ZeeGee Software, Inc. All rights reserved.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">This program is free software; you can redistribute it and\/or modify it under the same terms as Perl itself.<\/p>\n<hr>\n","protected":false},"excerpt":{"rendered":"<p>  IO::Scalar \u2212 IO:: interface for reading\/writing a scalar <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[3458,3007],"class_list":["post-7119","post","type-post","status-publish","format-standard","hentry","category-sin-categoria","tag-ioscalar","tag-man3"],"gutentor_comment":0,"_links":{"self":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/7119","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/comments?post=7119"}],"version-history":[{"count":0,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/7119\/revisions"}],"wp:attachment":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/media?parent=7119"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/categories?post=7119"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/tags?post=7119"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}