Re: Anyone using Ruby for scripting?

  • From: Jared Still <jkstill@xxxxxxxxx>
  • To: William.Blanchard@xxxxxxxxxxxxx
  • Date: Mon, 20 Sep 2010 11:01:45 -0700

On Mon, Sep 20, 2010 at 6:29 AM, Blanchard, William G <
William.Blanchard@xxxxxxxxxxxxx> wrote:

>   I can write a perl one-liner that edits a file but can’t, from within a
> perl script, directly edit a file.
>
>
Really?

I don't think you've tried hard enough.  :)

#!/usr/bin/perl

open TEST, ">test.txt";

print TEST "this is  a test\n";

open TEST, "test.txt";
my $l = <TEST>;
print "TEST before edit: $l";

open TEST, "+<test.txt";

seek TEST, 5, 0;

print TEST "was";

open TEST, "test.txt";
$l = <TEST>;
print "TEST after edit: $l";


Jared Still
Certifiable Oracle DBA and Part Time Perl Evangelist
Oracle Blog: http://jkstill.blogspot.com
Home Page: http://jaredstill.com

Other related posts: