its not that I do not understand its purpose, but maybe how to use it??? I 
am curious b/c this has worked for me before in other programs.  I will 
send this whole code.


Derek B. Smith
OhioHealth IT
UNIX / TSM / EDM Teams
614-566-4145





[EMAIL PROTECTED] (Peter Scott)
Sent by: [EMAIL PROTECTED] (Peter Scott)
09/16/2004 08:36 AM
Please respond to Peter

 
        To:     [EMAIL PROTECTED]
        cc: 
        Subject:        Re: $ ^ I   in place editor


In article 
<[EMAIL PROTECTED]>,
 [EMAIL PROTECTED] writes:
>In my code I am not understanding why my in place edit does not work? 
Here 
>is my code:
>
>use strict;
>use diagnostics;
>use warnings;

Good!

>my stps="/usr/local/log/scratchtps";
>
>   open (TP, ">$stps") || die "could not open file:$!";
>        open (TP2, ">$irmt ") || die "could not open file:$!";
>        open (D, "$logf") || die "could not open file:$!";
>        ($^I, @ARGV) = ('.bak', $scratchtps);
 
I think you copied this line from somewhere without understanding it.

>         print TP "\n";
>         print TP "Print Date: $dm\n";
>         print TP "EDM Scratch Tapes. Please have these returned from 
>IronMt.\n";
>         print TP "- - - - - - - - - - - - - - - - - - - - - - - - - - - 
- 
>- -\n";
>
>         while (<D>) {
>
>                ## look for 9840S and ebexpire
>                ## declare OFS = tab
>                ## tell split to split on IRS 0,1&5.
>
>                if ( (($_ =~ /9840S/) && ($_ =~ /ebexpire, ebexpire/)) && 

>(($_ =~ $dm) || ($_ =~ $dmm)) ) {
>                        local $, = "\t";
>                        print TP +(split)[0,1,5], $/ ;
>                        print TP2 +(split)[5], $/ ;
>                        system ("sort -k3 $stps > $scratchtps");
>                        system ("sort -k3 $irmt > $IRMTscratchtps");
>                }
>        }
>        close (TP);
>        close (TP2);
>        close (D);

Nowhere do you use the contents of @ARGV.  In-place edit only works
when you use the diamond operator (<>) for I/O, and you haven't.
So, having defined $^I and set @ARGV, you then need a loop:

        while (<>) {
                # Do something with $_
                # print something to default filehandle
        }

Whatever you print to the default filehandle inside that loop will
go to the new file.

-- 
Peter Scott
http://www.perldebugged.com/
*** NEW *** http://www.perlmedic.com/

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to