Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>What would I need to do from here to back up the file pointer so it writes to the same line I'm reading from?</p> </blockquote> <p>This doesn't help, unless every line you intend to write is the same length as the line you're replacing (in which case the tools you're looking for are <a href="http://perldoc.perl.org/functions/seek.html" rel="nofollow noreferrer">seek</a> and <a href="http://perldoc.perl.org/functions/tell.html" rel="nofollow noreferrer">tell</a>). For ordinary editing though, the standard file model just doesn't cut it for replacing bits in-place.</p> <p>Fortunately, Perl comes with a feature that makes what you need easy, called "in-place editing mode", in which the source file is either renamed or unlinked, and the output directed to a new file with the same name. Most often it's used by enabling the <code>-i</code> <a href="http://perldoc.perl.org/perlrun.html#Command-Switches" rel="nofollow noreferrer">command-line switch</a> together with the <code>-p</code> or <code>-n</code> switches for line-wise editing, but you can also enable it within a program using the <code>$^I</code> <a href="http://perldoc.perl.org/perlvar.html" rel="nofollow noreferrer">special variable</a>.</p> <p>Example code:</p> <pre><code>{ # Create a scope to localize variables in. # If you want to back up the originals, set $^I to ".bak" instead. local $^I = ""; # Set @ARGV to the file you want to process, or a list of files. local @ARGV = ("file.txt"); while (my $line = &lt;&gt;) { # Process $line here. print $line; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload