Perl in place editing within a script (rather than one liner)

前端 未结 1 1427
不思量自难忘°
不思量自难忘° 2020-12-29 12:41

So, I\'m used to the perl -i to use perl as I would sed and in place edit.

The docs for $^I in perlvar:

相关标签:
1条回答
  • 2020-12-29 13:09

    The edit-in-place behaviour that is enabled by the -i command-line option or by setting $^I works only on the ARGV file handle. That means the files must either be named on the command line or @ARGV must be set up within the program

    This program will change all lower-case letters to upper-case in all CSV files. Note that I have set $^I to a non-null string, which is advisable while you are testing so that your original data files are retained

    use strict;
    use warnings;
    
    our $^I = '.bak';
    
    while ( my $file = glob '*.csv' ) {
    
      print "Processing $file\n";
    
      our @ARGV = ($file);
    
      while ( <ARGV> ) {
         tr/a-z/A-Z/;
         print;
      }
    }
    
    0 讨论(0)
提交回复
热议问题