Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Actually it's not impossible to modify any type of file "in place". Just for Fun ... to update a file "in place".

... open(my $READER,'+<',$Filename_S) or die "Can't open '$Filename_S'! $!"; open(my $WRITER,'+<',$Filename_S) # Don't use + '+>' or die "Can't open '$Filename_S'! $!"; # The overflow buffer: my @Buffer_a; while (<$READER>) { # Read (past tense) a line - buffer its replacement ... # Modify the line here! my $Update_s=... push(@Buffer_a,$Update_s); # Write from the overflow buffer if we can ... while (@Buffer_a && length($Buffer_a[0]) < tell($READER)-tell( +$WRITER)) { # Enough room to write $Buffer_a[0] so write it ... print $WRITER shift(@Buffer_a); }; }; # Nothing more to read ... close($READER) or die "Can't close '$Filename_S'! $!"; # If there's anything in the buffer write it ... while (@Buffer_a) { print $WRITER shift(@Buffer_a); }; # Truncate the file, in case, what we're writing is shorter than w +hat we read truncate($WRITER,tell($WRITER)); # ... and close close($WRITER) or die "Can't close '$Filename_S'! $!"; ...
Be aware that if something should happen during the update one may be "up the creek without a paddle".

In reply to Re^2: Modify csv file. by clueless newbie
in thread Modify csv file. by bimleshsharma

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 admiring the Monastery: (5)
As of 2024-04-23 16:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found