Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
erikharrison is dead on. In order for your existing program to work, you really have to open a temp file, write to it, then clob the first file by moving the temp file over the first file:
use strict; use IO::File; my $in = IO::File->new; my $out = IO::File->new; my $change_on = "FChangeBar Yes"; my $change_off = "FchangeBar No"; # hmmm, lower case c? $in->open('test.mif') or die "can't read input"; $out->open('>tmp.mif') or die "can't write output"; while (<$in>) { s/$change_on/$change_off/g; print $out $_; } $in->close or die "can't close input"; $out->close or die "can't close output"; rename('tmp.mif','test.mif') or die "can't rename";
Here is a much cooler version that uses Tie::File:
use strict; use Tie::File; my @file; tie @file, 'Tie::File', 'test.mif' or die "cannot tie file"; s/(FchangeBar )Yes/$1No/g for @file;
But, you might not be able to incorporate this into your ending program. At any rate, you are welcome and good luck! :)

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

In reply to (jeffa) 3Re: Unable to save changes using IO::File by jeffa
in thread Unable to save changes using IO::File by pelp

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (2)
As of 2024-04-20 06:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found