in-place file editing once script started 
Author Message
 in-place file editing once script started

There is a command-line flag to perform in-place editing of a file.
Unfortunately, that only works if you know before the program starts
that a file should be edited in-place. Let's say i want to
interactively determine which editing mode should be used. Is there a
way to achieve the same effect using a pragma, function or option? Of
course,it's always possible to spawn a new Perl process possessing the
appropriate flag, but that's not my idea of clean.

Tom Legrady



Tue, 28 Sep 2004 21:58:55 GMT  
 in-place file editing once script started
: There is a command-line flag to perform in-place editing of a file.
: Unfortunately, that only works if you know before the program starts
: that a file should be edited in-place. Let's say i want to
: interactively determine which editing mode should be used. Is there a
: way to achieve the same effect using a pragma, function or option? Of
: course,it's always possible to spawn a new Perl process possessing the
: appropriate flag, but that's not my idea of clean.

example: add line numbers to some files, and save the original

        #!perl
        # try.pl

        $^I = ".BACK";

        while (<>)
        {
                print "$.: $_";      
        }

e.g. usage.  modify files x y and z in place.

        $ perl try.pl x y z



Wed, 29 Sep 2004 00:31:21 GMT  
 in-place file editing once script started

Quote:

>There is a command-line flag to perform in-place editing of a file.
>Is there a
>way to achieve the same effect using a pragma, function or option?

                                        ^^^^^^  ^^^^^^^^    ^^^^^^

No.

But it _is_ possible using a special variable:

   $^I = '.bak' if $I_want_inplace_editing;

--
    Tad McClellan                          SGML consulting

    Fort Worth, Texas



Tue, 28 Sep 2004 23:33:46 GMT  
 in-place file editing once script started

Quote:

> >Is there a way to achieve inplace editing using a pragma ... ?
> it _is_ possible using a special variable:

>    $^I = '.bak' if $I_want_inplace_editing;

Thanks Tad! I knew I had seen something. Why is it so easy to remember
things, right up to the time when you need them? :-)

Tom



Wed, 29 Sep 2004 19:58:13 GMT  
 in-place file editing once script started

Quote:

>Why is it so easy to remember
>things, right up to the time when you need them? :-)

Because Murphy never sleeps.

--
    Tad McClellan                          SGML consulting

    Fort Worth, Texas



Wed, 29 Sep 2004 23:50:13 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. inplace editing ($^I) and file locking

2. Inplace file editing within a perl program

3. in place edit without commiting script to loop

4. inplace editing

5. Inplace edits using -i.bak

6. inplace edit

7. Inplace Editing

8. inplace editing question.

9. Help with inplace editing

10. Inplace editing and safety

11. In-place edit works on read-only files!!!

12. perl edit in place file globbing problem on windows

 

 
Powered by phpBB® Forum Software