CINXE.COM

open | Raku Documentation

<!DOCTYPE html> <html lang="en" class="fontawesome-i2svg-active fontawesome-i2svg-complete" style="scroll-padding-top:60px"> <head> <title>open | Raku Documentation</title> <meta charset="UTF-8" /> <link href="/assets/images/Camelia.ico" rel="icon" type="image/x-icon"/> <link rel="stylesheet" href="/assets/css/Website.css"/> <link rel="stylesheet" href="/assets/css/typegraph-styling.css"/> <link rel="stylesheet" href="/assets/css/typegraph-dark.css" title="dark"/> <link rel="stylesheet" href="/assets/css/typegraph-light.css" title="light"/> <link rel="stylesheet" href="/assets/css/css/filtered-toc-dark.css" title="dark"/> <link rel="stylesheet" href="/assets/css/css/filtered-toc-light.css" title="light"/> <link rel="stylesheet" href="/assets/css/css/announce-light.css" title="light"/> <link rel="stylesheet" href="/assets/css/css/announce-dark.css" title="dark"/> <link rel="stylesheet" href="/assets/css/all.min.css"/> <link rel="stylesheet" href="/assets/css/listf-styling-light.css" title="light"/> <link rel="stylesheet" href="/assets/css/listf-styling-dark.css" title="dark"/> <link rel="stylesheet" href="/assets/css/css/options-search-light.css" title="light"/> <link rel="stylesheet" href="/assets/css/css/options-search-dark.css" title="dark"/> <link rel="stylesheet" href="/assets/css/css/page-styling-main.css"/> <link rel="stylesheet" href="/assets/css/css/page-styling-dark.css" title="dark"/> <link rel="stylesheet" href="/assets/css/css/page-styling-light.css" title="light"/> <link rel="stylesheet" href="/assets/css/css/chyronToggle-dark.css" title="dark"/> <link rel="stylesheet" href="/assets/css/css/chyronToggle-light.css" title="light"/> <link rel="stylesheet" href="/assets/css/css/centreToggle-dark.css" title="dark"/> <link rel="stylesheet" href="/assets/css/css/centreToggle-light.css" title="light"/> <link rel="stylesheet" href="/assets/css/tm-styling.css"/> <link rel="stylesheet" href="/assets/css/tm-light.css" title="light"/> <link rel="stylesheet" href="/assets/css/tm-dark.css" title="dark"/> <link rel="stylesheet" href="/assets/css/css/rainbow-dark.css" title="dark"/> <link rel="stylesheet" href="/assets/css/css/rainbow-light.css" title="light"/> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@tarekraafat/autocomplete.js@10.2.7/dist/css/autoComplete.min.css" /> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/atom-one-light.min.css" title="light" /> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/atom-one-dark.min.css" title="dark" /> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script> <script src="/assets/scripts/all.min.js"></script><script src="/assets/scripts/filter-script.js"></script><script src="/assets/scripts/tableManager.js"></script><script src="https://cdn.jsdelivr.net/npm/fuzzysort@2.0.4/fuzzysort.min.js"></script><script src="https://cdn.jsdelivr.net/npm/@tarekraafat/autocomplete.js@10.2.7/dist/autoComplete.min.js"></script><script src="/assets/scripts/filtered-toc.js"></script><script src="/assets/scripts/options-search.js"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/languages/haskell.min.js"></script><script src="/assets/scripts/page-styling.js"></script><script src="/assets/scripts/announcements.js"></script><script src="/assets/scripts/rainbow.js"></script> </head> <body class="has-navbar-fixed-top"> <nav class="navbar is-fixed-top is-flex-touch" role="navigation" aria-label="main navigation"> <div class="navbar-item" style="margin-left: auto;"> <div class="left-bar-toggle" title="Toggle Table of Contents & Index"> <label class="chyronToggle left"> <input id="navbar-left-toggle" type="checkbox"> <span class="text">Contents</span> </label> </div> </div> <div class="container is-justify-content-space-around"> <div class="navbar-brand"> <div class="navbar-logo"> <a class="navbar-item" href="/"> <img src="/assets/images/camelia-recoloured.png" alt="Raku" width="52.83" height="38"> </a> <span class="navbar-logo-tm">tm</span> </div> <a role="button" class="navbar-burger burger" aria-label="menu" aria-expanded="false" data-target="navMenu"> <span aria-hidden="true"></span> <span aria-hidden="true"></span> <span aria-hidden="true"></span> </a> </div> <div id="navMenu" class="navbar-menu"> <div class="navbar-start"> <a class="navbar-item" href="/introduction" title="Getting started, Tutorials, Migration guides"> Introduction </a> <a class="navbar-item" href="/reference" title="Fundamentals, General reference"> Reference </a> <a class="navbar-item" href="/miscellaneous" title="Programs, Experimental"> Miscellaneous </a> <a class="navbar-item" href="/types" title="The core types (classes) available"> Types </a> <a class="navbar-item" href="/routines" title="Searchable table of routines"> Routines </a> <a class="navbar-item" href="https://raku.org" title="Home page for community"> Raku<sup>®</sup> </a> <a class="navbar-item" href="https://web.libera.chat/#raku" title="IRC live chat"> Chat </a> <div class="navbar-item has-dropdown is-hoverable"> <a class="navbar-link"> More </a> <div class="navbar-dropdown is-right is-rounded"> <hr class="navbar-divider"> <a class="navbar-item js-modal-trigger" data-target="download-ebook"> Download E-Book (epub) </a> <hr class="navbar-divider"> <a class="navbar-item" href="/about"> About </a> <hr class="navbar-divider"> <a class="navbar-item has-text-red" href="https://github.com/raku/doc-website/issues"> Report an issue with this site </a> <hr class="navbar-divider"> <a class="navbar-item" href="https://github.com/raku/doc/issues"> Report an issue with the documentation content </a> <hr class="navbar-divider"> <label class="navbar-item centreToggle" title="Enable/Disable Announcements" style="--switch-width: 18"> <input id="cancelAnnouncements" type="checkbox"> <span class="text">Announcements</span> <span class="on">suppressed</span> <span class="off">allowed</span> </label> </div> </div> </div> <div class="navbar-end navbar-search-wrapper"> <div class="navbar-item"> <div class="field has-addons"> <div class="autoComplete_options"> <input class="control input" id="autoComplete" type="search" dir="ltr" spellcheck=false autocorrect="off" autocomplete="off" autocapitalize="off" placeholder="🔍 Type f to search for ..."> </div> <div class="control" title="Search options"> <a class="button is-primary js-modal-trigger" data-target="options-search-info"> <span class="icon"> <i class="fas fa-cogs"></i> </span> </a> </div> </div> </div> </div> <div id="options-search-info" class="modal"> <div class="modal-background"></div> <div class="modal-content"> <div class="box"> <p>The last search was: <span id="selected-candidate" class="ss-selected"></span></p> <div class="control is-grouped is-grouped-centered options-search-controls"> <label class="centreToggle" title="Include extra information (Alt-E)" style="--switch-width: 10.5"> <input id="options-search-extra" type="checkbox"> <span class="text">Extra info</span> <span class="on">yes</span> <span class="off">no</span> </label> <p>The search response can be shortened by excluding the extra information line (Alt-E)</p> <label class="centreToggle" title="Search engine type Strict/Loose (Alt-L)" style="--switch-width: 10.5"> <input id="options-search-loose" type="checkbox"> <span class="text">Search type</span> <span class="on">loose</span> <span class="off">strict</span> </label> <p> The search engine can perform a strict search (only the characters in the search box) or a loose search (Alt-L)</p> <label class="centreToggle" title="Search in headings (Alt-H)" style="--switch-width: 10.5"> <input id="options-search-headings" type="checkbox"> <span class="text">Headings</span> <span class="on">yes</span> <span class="off">no</span> </label> <p>Search through headings in all web-pages (Alt-H)</p> <label class="centreToggle" title="Search indexed items (Alt-I)" style="--switch-width: 10.5"> <input id="options-search-indexed" type="checkbox"> <span class="text">Indexed</span> <span class="on">yes</span> <span class="off">no</span> </label> <p>Search through all indexed items (Alt-I)</p> <label class="centreToggle" title="Search composite pages (Alt-C)" style="--switch-width: 10.5"> <input id="options-search-composite" type="checkbox"> <span class="text">Composite</span> <span class="on">yes</span> <span class="off">no</span> </label> <p>Search in the names of composite pages, which combine similar information from the main web pages (Alt-C)</p> <label class="centreToggle" title="Search primary sources (Alt-P)" style="--switch-width: 10.5"> <input id="options-search-primary" type="checkbox"> <span class="text">Primary</span> <span class="on">yes</span> <span class="off">no</span> </label> <p>Search through the names of the main web pages (Alt-P)</p> <label class="centreToggle" title="Open in new tab (Alt-Q)" style="--switch-width: 10.5"> <input id="options-search-newtab" type="checkbox"> <span class="text">New tab</span> <span class="on">yes</span> <span class="off">no</span> </label> <p>Once a search candidate has been chosen, it can be opened in a new tab or in the current tab (Alt-Q)</p> <p>If all else fails, an item is added to use the Google search engine on the whole site</p> <button class="button is-warning" id="options-search-reset-defaults">Clear options, reset to defaults</button> <p>Exit this page by pressing &lt;Escape&gt;, or clicking on X or on the background.</p> </div> </div> </div> <button class="modal-close is-large" aria-label="close"></button> </div> </div> <div id="download-ebook" class="modal"> <div class="modal-background"></div> <div class="modal-content"> <div class="box"> <p><a href="/RakuDocumentation.epub" download>RakuDocumentation.epub</a> is a work in progress e-book. It targets the <a href="https://www.w3.org/publishing/epub3/">EPUB v3 specification</a>. It needs testing on a variety of ereaders (some of which may still implicitly expect compliance with EPUB v2). The CSS definitely needs enhancing (especially for code snippets). The Ebook opens in a Calibre reader, which is available on all operating systems.</p> <p>Suggestions are welcome and should be addressed by opening an issue on the Raku/doc-website repository</p> <p>Exit this popup by pressing &lt;Escape&gt;, or clicking on X or on the background.</p> </div> </div> <button class="modal-close is-large" aria-label="close"></button> </div> <div id="announcement-modal" class="modal"> <div class="modal-background"></div> <div class="modal-content"> <div class="box"> <div id="raku-doc-announcement"></div> <p>For more see <a href="/announcements">Announcements page</a>.</p> <p>Exit this popup by pressing &lt;Escape&gt;, or clicking on X or on the background.</p> </div> </div> <button class="modal-close is-large" aria-label="close"></button> </div> </div> </nav> <div class="tile is-ancestor section"> <div class="page-edit"> <a class="button js-modal-trigger" data-target="page-edit-info"> <span class="icon"> <i class="fas fa-pen-alt is-medium"></i> </span> </a> </div> <div id="page-edit-info" class="modal"> <div class="modal-background"></div> <div class="modal-content"> <div class="box"> <p>This is an automatically generated page and cannot be edited directly. Text in Composite pages, (URLs starting with 'routine' or 'syntax') can be edited by clicking on the link labeled 'in context', and editing the text there.</p> <p>Exit this popup by pressing &lt;Escape&gt;, or clicking on X or on the background.</p> </div> </div> <button class="modal-close is-large" aria-label="close"></button> </div> <div id="left-column" class="tile is-parent is-2 is-hidden"> <div id="left-col-inner"> <div class="tabs" id="tabs"> <ul> <li class="is-active" id="toc-tab"> <a>Table of Contents</a> </li> <li id="index-tab"> <a>Index</a> </li> </ul> </div> <div class="field"> <div class="control has-icons-right"> <input id="toc-filter" class="input" type="text" placeholder="Filter"> <span class="icon is-right has-text-grey"> <i class="fas fa-search is-medium"></i> </span> </div> </div> <div class="raku-sidebar"> <aside id="toc-menu" class="menu"> <ul class="menu-list"> <li><a href="#(IO::Handle)_method_open">In IO::Handle</a></li> <li><a href="#(IO::Path)_method_open">In IO::Path</a></li> <li><a href="#(IO::CatHandle)_method_open">In IO::CatHandle</a></li> <li><a href="#(Independent_routines)_sub_open">In Independent routines</a></li> </ul> </aside> <aside id="index-menu" class="menu is-hidden"> </aside> </div> </div> </div> <div id="main-column" class="tile is-parent" style="overflow-x: hidden;"> <div id="main-col-inner"> <section class="raku page-header"> <div class="container px-4"> <div class="raku page-title has-text-centered"> open </div> <div class="raku page-subtitle has-text-centered"> Combined from primary sources listed below. </div> </div> </section> <section class="raku page-content"><div class="container px-4"><div class="columns one-col"> <h1 id="(IO::Handle)_method_open" class="raku-h1"><a href="#___top" title="go to top of document">In IO::Handle<a class="raku-anchor" title="direct link" href="#(IO::Handle)_method_open">§</a></a></h1> <p> See primary documentation <a href="/type/IO/Handle#method_open">in context</a> for <b>method open</b>. </p><div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-KEYWORD">method</span> <span class="highlite-ROUTINE">open</span>(IO::Handle:D: <span class="highlite-OPERATOR">:</span><span class="highlite-NAME_SCALAR">$r</span><span class="highlite-OPERATOR">,</span> <span class="highlite-OPERATOR">:</span><span class="highlite-NAME_SCALAR">$w</span><span class="highlite-OPERATOR">,</span> <span class="highlite-OPERATOR">:</span><span class="highlite-NAME_SCALAR">$x</span><span class="highlite-OPERATOR">,</span> <span class="highlite-OPERATOR">:</span><span class="highlite-NAME_SCALAR">$a</span><span class="highlite-OPERATOR">,</span> <span class="highlite-OPERATOR">:</span><span class="highlite-NAME_SCALAR">$update</span><span class="highlite-OPERATOR">,</span> <span class="highlite-OPERATOR">:</span><span class="highlite-NAME_SCALAR">$rw</span><span class="highlite-OPERATOR">,</span> <span class="highlite-OPERATOR">:</span><span class="highlite-NAME_SCALAR">$rx</span><span class="highlite-OPERATOR">,</span> <span class="highlite-OPERATOR">:</span><span class="highlite-NAME_SCALAR">$ra</span><span class="highlite-OPERATOR">,</span> <span class="highlite-OPERATOR">:</span><span class="highlite-NAME_SCALAR">$mode</span> <span class="highlite-KEYWORD">is</span> <span class="highlite-ROUTINE">copy</span><span class="highlite-OPERATOR">,</span> <span class="highlite-OPERATOR">:</span><span class="highlite-NAME_SCALAR">$create</span> <span class="highlite-KEYWORD">is</span> <span class="highlite-ROUTINE">copy</span><span class="highlite-OPERATOR">,</span> <span class="highlite-OPERATOR">:</span><span class="highlite-NAME_SCALAR">$append</span> <span class="highlite-KEYWORD">is</span> <span class="highlite-ROUTINE">copy</span><span class="highlite-OPERATOR">,</span> <span class="highlite-OPERATOR">:</span><span class="highlite-NAME_SCALAR">$truncate</span> <span class="highlite-KEYWORD">is</span> <span class="highlite-ROUTINE">copy</span><span class="highlite-OPERATOR">,</span> <span class="highlite-OPERATOR">:</span><span class="highlite-NAME_SCALAR">$exclusive</span> <span class="highlite-KEYWORD">is</span> <span class="highlite-ROUTINE">copy</span><span class="highlite-OPERATOR">,</span> <span class="highlite-OPERATOR">:</span><span class="highlite-NAME_SCALAR">$bin</span><span class="highlite-OPERATOR">,</span> <span class="highlite-OPERATOR">:</span><span class="highlite-NAME_SCALAR">$enc</span> <span class="highlite-KEYWORD">is</span> <span class="highlite-ROUTINE">copy</span><span class="highlite-OPERATOR">,</span> <span class="highlite-OPERATOR">:</span><span class="highlite-NAME_SCALAR">$chomp</span> <span class="highlite-OPERATOR">=</span> <span class="highlite-NAME_SCALAR">$!chomp</span><span class="highlite-OPERATOR">,</span> <span class="highlite-OPERATOR">:</span><span class="highlite-NAME_SCALAR">$nl-in</span> <span class="highlite-KEYWORD">is</span> <span class="highlite-ROUTINE">copy</span> <span class="highlite-OPERATOR">=</span> <span class="highlite-NAME_SCALAR">$!nl-in</span><span class="highlite-OPERATOR">,</span> Str:D <span class="highlite-OPERATOR">:</span><span class="highlite-NAME_SCALAR">$nl-out</span> <span class="highlite-KEYWORD">is</span> <span class="highlite-ROUTINE">copy</span> <span class="highlite-OPERATOR">=</span> <span class="highlite-NAME_SCALAR">$!nl-out</span><span class="highlite-OPERATOR">,</span> <span class="highlite-OPERATOR">:</span><span class="highlite-NAME_SCALAR">$out-buffer</span> <span class="highlite-KEYWORD">is</span> <span class="highlite-ROUTINE">copy</span><span class="highlite-OPERATOR">,</span> ) </pre> </div> </div> <p>Opens the handle in one of the modes. <a href="/routine/fail">Fails</a> with appropriate exception if the open fails.</p><p>See description of individual methods for the accepted values and behavior of <a href="/type/IO/Handle#method_chomp"><code>:$chomp</code></a>, <a href="/type/IO/Handle#method_nl-in"><code>:$nl-in</code></a>, <a href="/type/IO/Handle#method_nl-out"><code>:$nl-out</code></a>, and <a href="/type/IO/Handle#method_encoding"><code>:$enc</code></a>. The values for parameters default to the invocant's attributes and if any of them are provided, the attributes will be updated to the new values. Specify <code>:$bin</code> set to <code>True</code> instead of <code>:$enc</code> to indicate the handle should be opened in binary mode. Specifying undefined value as <code>:$enc</code> is equivalent to not specifying <code>:$enc</code> at all. Specifying both a defined encoding as <code>:$enc</code> and <code>:$bin</code> set to true will cause <code>X::IO::BinaryAndEncoding</code> exception to be thrown.</p><p>The open mode defaults to non-exclusive, read only (same as specifying <code>:r</code>) and can be controlled by a mix of the following arguments:</p> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>「text」 without highlighting</label> <div> <pre class="nohighlights"><pre class="nohighlights"> :r same as specifying :mode&lt;ro&gt; same as specifying nothing :w same as specifying :mode&lt;wo&gt;, :create, :truncate :a same as specifying :mode&lt;wo&gt;, :create, :append :x same as specifying :mode&lt;wo&gt;, :create, :exclusive :update same as specifying :mode&lt;rw&gt; :rw same as specifying :mode&lt;rw&gt;, :create :ra same as specifying :mode&lt;rw&gt;, :create, :append :rx same as specifying :mode&lt;rw&gt;, :create, :exclusive </pre> </pre> </div> </div> <p>Argument <code>:r</code> along with <code>:w</code>, <code>:a</code>, <code>:x</code> are exactly the same as the combination of both letters, shown in the three last rows in the table above. Support for combinations of modes <em>other</em> than what is listed above is implementation-dependent and should be assumed unsupported. That is, specifying, for example, <code>.open(:r :create)</code> or <code>.open(:mode&lt;wo&gt; :append :truncate)</code> might work or might cause the Universe to implode, depending on a particular implementation. This applies to reads/writes to a handle opened in such unsupported modes as well.</p><p>The mode details are:</p> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>「text」 without highlighting</label> <div> <pre class="nohighlights"><pre class="nohighlights"> :mode&lt;ro&gt; means &quot;read only&quot; :mode&lt;wo&gt; means &quot;write only&quot; :mode&lt;rw&gt; means &quot;read and write&quot; :create means the file will be created, if it does not exist :truncate means the file will be emptied, if it exists :exclusive means .open will fail if the file already exists :append means writes will be done at the end of file's current contents </pre> </pre> </div> </div> <p>Attempts to open a directory, write to a handle opened in read-only mode or read from a handle opened in write-only mode, or using text-reading methods on a handle opened in binary mode will fail or throw.</p><p>In <strong>6.c</strong> language, it's possible to open path <code>'-'</code>, which will cause <code>open</code> to open (if <code>closed</code>) the <code>$*IN</code> handle if opening in read-only mode or to open the <code>$*OUT</code> handle if opening in write-only mode. All other modes in this case will result in exception being thrown.</p><p>As of <strong>6.d</strong> language version, the use of path <code>'-'</code> is deprecated and it will be removed in future language versions entirely.</p><p>The <code>:out-buffer</code> controls output buffering and by default behaves as if it were <a href="/type/Nil"><code>Nil</code></a>. See method <a href="/routine/out-buffer">out-buffer</a> for details.</p><p><strong>Note (Rakudo versions before 2017.09): Filehandles are NOT flushed or closed when they go out of scope</strong>. While they <em>will</em> get closed when garbage collected, garbage collection isn't guaranteed to get run. This means <em>you should</em> use an explicit <code>close</code> on handles opened for writing, to avoid data loss, and an explicit <code>close</code> is <em>recommended</em> on handles opened for reading as well, so that your program does not open too many files at the same time, triggering exceptions on further <code>open</code> calls.</p><p><strong>Note (Rakudo versions 2017.09 and after):</strong> Open filehandles are automatically closed on program exit, but it is still highly recommended that you <code>close</code> opened handles explicitly.</p> <h1 id="(IO::Path)_method_open" class="raku-h1"><a href="#___top" title="go to top of document">In IO::Path<a class="raku-anchor" title="direct link" href="#(IO::Path)_method_open">§</a></a></h1> <p> See primary documentation <a href="/type/IO/Path#method_open">in context</a> for <b>method open</b>. </p><div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-KEYWORD">method</span> <span class="highlite-ROUTINE">open</span>(IO::Path:D: <span class="highlite-OPERATOR">*</span><span class="highlite-NAME_HASH">%opts</span>)</pre> </div> </div> <p>Opens the path as a file; the named options control the mode, and are the same as the <a href="/routine/open">open</a> function accepts.</p> <h1 id="(IO::CatHandle)_method_open" class="raku-h1"><a href="#___top" title="go to top of document">In IO::CatHandle<a class="raku-anchor" title="direct link" href="#(IO::CatHandle)_method_open">§</a></a></h1> <p> See primary documentation <a href="/type/IO/CatHandle#method_open">in context</a> for <b>method open</b>. </p><div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-KEYWORD">method</span> <span class="highlite-ROUTINE">open</span>(IO::CatHandle:D: <span class="highlite-KEYWORD">--&gt;</span> IO::CatHandle:D)</pre> </div> </div> <p>Returns the invocant. The intent of this method is to merely make CatHandle workable with things that open <a href="/type/IO/Handle"><code>IO::Handle</code></a>. You never have to call this method intentionally.</p> <h1 id="(Independent_routines)_sub_open" class="raku-h1"><a href="#___top" title="go to top of document">In Independent routines<a class="raku-anchor" title="direct link" href="#(Independent_routines)_sub_open">§</a></a></h1> <p> See primary documentation <a href="/type/independent-routines#sub_open">in context</a> for <b>sub open</b>. </p><div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-KEYWORD">multi</span> <span class="highlite-ROUTINE">open</span>(<span class="highlite-TYPE">IO</span>() <span class="highlite-NAME_SCALAR">$path</span><span class="highlite-OPERATOR">,</span> |<span class="highlite-ROUTINE">args</span> <span class="highlite-KEYWORD">--&gt;</span> IO::Handle:D)</pre> </div> </div> <p>Creates <a href="/type/IO/Handle">a handle</a> with the given <code>$path</code>, and calls <a href="/type/IO/Handle#method_open"><code>IO::Handle.open</code></a>, passing any of the remaining arguments to it. Note that <a href="/type/IO/Path"><code>IO::Path</code></a> type provides numerous methods for reading and writing from files, so in many common cases you do not need to <code>open</code> files or deal with <a href="/type/IO/Handle"><code>IO::Handle</code></a> type directly.</p> <div class="raku-code raku-lang"> <button class="copy-code" title="Copy code"><i class="far fa-clipboard"></i></button> <label>Raku highlighting</label> <div> <pre class="nohighlights"><span class="highlite-KEYWORD">my</span> <span class="highlite-NAME_SCALAR">$fh</span> <span class="highlite-OPERATOR">=</span> <span class="highlite-ROUTINE">open</span> :w<span class="highlite-OPERATOR">,</span> <span class="highlite-STRING_DELIMITER">'</span><span class="highlite-STRING">/tmp/some-file.txt</span><span class="highlite-STRING_DELIMITER">'</span>; <span class="highlite-NAME_SCALAR">$fh</span>.say: <span class="highlite-STRING_DELIMITER">'</span><span class="highlite-STRING">I ♥ writing Raku code</span><span class="highlite-STRING_DELIMITER">'</span>; <span class="highlite-NAME_SCALAR">$fh</span>.<span class="highlite-ROUTINE">close</span>; <span class="highlite-NAME_SCALAR">$fh</span> <span class="highlite-OPERATOR">=</span> <span class="highlite-ROUTINE">open</span> <span class="highlite-STRING_DELIMITER">'</span><span class="highlite-STRING">/tmp/some-file.txt</span><span class="highlite-STRING_DELIMITER">'</span>; <span class="highlite-ROUTINE">print</span> <span class="highlite-NAME_SCALAR">$fh</span>.readchars: 4; <span class="highlite-NAME_SCALAR">$fh</span>.seek: 7<span class="highlite-OPERATOR">,</span> SeekFromCurrent; <span class="highlite-ROUTINE">say</span> <span class="highlite-NAME_SCALAR">$fh</span>.readchars: 4; <span class="highlite-NAME_SCALAR">$fh</span>.<span class="highlite-ROUTINE">close</span>; <span class="highlite-COMMENT"># OUTPUT: «I ♥ Raku␤» </span></pre> </div> </div></div></div></section> </div> </div> </div> <footer class="footer main-footer"> <div class="container px-4"> <nav class="level"> <div class="level-left"> <div class="level-item"> <a href="/about">About</a> </div> <div class="level-item"> <a id="toggle-theme">Toggle theme</a> </div> </div> <div class="level-right"> <div class="level-item"> <a href="/license">License</a> </div> </div> </nav> </div> </footer> </body> </html>

Pages: 1 2 3 4 5 6 7 8 9 10