in reply to Delete the first line of a file ?
If I may suggest, a regex is not the best tool for the job here. Unless there is an overriding reason, it might be easier just to do something along the lines of:
my $filename = "blah.txt"; #replace as needed rename($filename, $filename . '.bak') or die("Unable to rename $filename to $filename.bak: $!\n"); open(INFILE, $filename . '.bak') or die("Can't open $filename.bak for input: $!\n"); open(OUTFILE, '>' . $filename) or die("Can't open $filename for output: $!\n"); my $linecount = 0; while ($line = <INFILE>) { print(OUTFILE $line) if ($linecount); $linecount++; } close(INFILE); close(OUTFILE);
Two references that cover this and more that I use frequently are the perl FAQs and Perl Cookbook, and there are others here and about.
Hope that helps. I look forward to seeing the responses of others as well.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Regex
by Anonymous Monk on Apr 25, 2018 at 08:51 UTC |