in reply to calculating lines
You don't want to use DATA as a user file handle. It's reserved for inline data after __END__, __DATA__, or Ctrl-Z.
I'll call the file handle $fh. Reading line by line,
convert all clusters of whitespace to a single space,while (<$fh>) {
get rid of initial whitespace to handle "\n\t" and such,s/\s+/ /g;
and print the lowercased line,s/$\s//;
That's it. Each of those operations takes advantage of $_ as the default argument.print lc; }
With that method, there's no need to do any special accounting of lines or to store any of your work as you go. If you do need to store the lines for some other purpose, you only need to push the output of lc onto an array where the print occurs.
If you just want a line count, you can immediately follow the while block with,
$. is a running linecount of the most recently accessed read handle. It will be volatile in an application with several read handles, hence the assignment to a user variable.my $linecount = $. ;
After Compline,
Zaxo
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: calculating lines
by Yoda_Oz (Sexton) on Jan 12, 2007 at 00:42 UTC | |
by Zaxo (Archbishop) on Jan 12, 2007 at 00:54 UTC | |
|
Re^2: calculating lines
by Yoda_Oz (Sexton) on Jan 12, 2007 at 01:35 UTC | |
by Zaxo (Archbishop) on Jan 12, 2007 at 01:44 UTC | |
|
Re^2: calculating lines
by Yoda_Oz (Sexton) on Jan 12, 2007 at 01:02 UTC | |
by Zaxo (Archbishop) on Jan 12, 2007 at 01:15 UTC | |
by Yoda_Oz (Sexton) on Jan 12, 2007 at 01:17 UTC |