Problems? Is your data what you think it is? | |
PerlMonks |
Re: Count the number of lines in a fileby BlaisePascal (Monk) |
on May 25, 2004 at 17:02 UTC ( [id://356292]=note: print w/replies, xml ) | Need Help?? |
I was once given a very similar problem as a test to show I knew minimal perl for a tech-support job I once had. It's also very similar to what I would expect from a homework assignment in an intro-to-perl class. It's also something I could see someone doing self-study in perl might choose as a sample problem to solve themselves. Either way, my answer is going to be the same: Read the documentation. Specifically, you'll probably want to open a file for reading and/or writing (check the perl docs for the "open" function), use a while loop to read each line in the file one by one (check the docs for the "while" statement), find the length of the line read (can you guess the function name to find the length of a string?), and possibly look up how to print stuff to a file. It's sort of cheating to do system("wc -lc $infile > $outfile"); in my opinion.
In Section
Seekers of Perl Wisdom
|
|