in reply to Removing lines from files
Aside from your immediate problem there are a couple of style issues to consider that may help you in the future. First, always use strictures (use strict; use warnings;). Strictures catch a lot of silly typos and similar errors before they get a chance to waste a few hours trying to find subtle errors.
Don't use prototypes for subroutines. While there are a small number of situations where they are useful, generally they don't do what you think and often do what you don't expect. In the case of your sample code the prototype is actually ignored in any case because it hasn't been seen before it is used!
In the interests of showing you a little more Perl power consider:
sub edits { return unless -f and /^33dc01\..*outer.log$/; # Set up for in place edit local @ARGV = ($_); local $^I = '.bak'; print "$File::Find::name\n"; while (<>) { print if $. > 4; } }
which uses Perl's in place edit facility to rewrite the file having skipped the first four lines. Note that this will create backups of the original files with .bak appended to the file name.
The special variable $. provides the current line number for the file handle most recently accessed. See $^I, @ARGV, $. and $ARGV (which I didn't use, but may be of interest).
|
|---|