[Chicago-talk] -i, -n and print - removing the top x lines w/ each run

Andy_Bach at wiwb.uscourts.gov Andy_Bach at wiwb.uscourts.gov
Thu Sep 27 13:20:32 PDT 2007

Got it - perldoc perlrun and the  -i switch showed me:
use warnings;
use strict;
my $oldargv = '';
my $argvout ;
while (<>) {
  if ($ARGV ne $oldargv) {
    my $backup = sprintf("%s_%d", $ARGV, $$);
    rename($ARGV, $backup);
    open($argvout, ">$ARGV");
    $oldargv = $ARGV;
  if ( 1 .. /--- End/ ) {
     next unless /\S/;
  print;  # this prints to original filename


Andy Bach
Systems Mangler
Internet: andy_bach at wiwb.uscourts.gov
VOICE: (608) 261-5738  FAX 264-5932

Nothing in life is certain except death, taxes and the second law of 
thermodynamics. All three are processes 
in which useful or accessible forms of some quantity, such as energy or 
money, are transformed into useless,
 inaccessible forms of the same quantity. That is not to say that these 
three processes don't have fringe benefits: 
taxes pay for roads and schools; the second law of thermodynamics drives 
cars, computers and metabolism; 
and death, at the very least, opens up tenured faculty positions.
Seth Lloyd

More information about the Chicago-talk mailing list