To skip over blanks lines in a perl script, you have several choices. You could use a "next if /^$/" (skip if empty) command or a "next if /^\s*$/" skip if empty or only white space.
Solution: Read in the first line, do your processing, then continue reading the file. #!/usr/bin/perl -w use strict; use warnings; my $file = "..."; open (CODE, $file) || die "Couldn't open $file: $!"; print scalar <CODE>; # Print the first line # ... Do your processing here ...
open(FILE,'file. txt'); while (<FILE>) print if eof; } close(FILE);
I do have a whole bunch of files in a directory and from every file I want to remove the first line (including carriage return). I can read the whole file into an array of strings and write all but the first element to a new file, but that looks a bit cumbersome to me are there better ways? Oh the prefered language is Perl.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With