in reply to no of lines in uploaded text file

I have tried wc -l. but didnt work.
Define "did not work". What did you try? What did you get? What did you expect? Did you get an error? If so, what was it? What did you try to fix the error?
Is there any way to get no of lines ?
Yes, but all of them require you to open the file, read in all the data, and somehow count the number of newlines. Which is what wc -l does as well. And if that "doesn't work", I don't have high hopes for any alternative method.

Replies are listed 'Best First'.
Re^2: no of lines in uploaded text file
by Anonymous Monk on May 12, 2010 at 09:16 UTC
    Thanx all for sharing your knowledge. Suggestion given by CountZero worked. I did same thing. I copied all whole file content into one array and used that array to get no of lines and content of file. I have still one query. When I used suggestion given by moritz my $count = 0; while( <$fh> ) { $count++; } I was unable to get content of file. I think the reason for this was that you cant reuse file handle. Can anyone tell me why this is so ? @JavaFan , I tried to use this $content = ` wc -l $Filehandle` but I could not get output in $count as it should be. This worked fine on command prompt bt not on browser. Regards, Prafull
      When I used suggestion given by moritz my $count = 0; while( <$fh> ) { $count++; } I was unable to get content of file. I think the reason for this was that you cant reuse file handle. Can anyone tell me why this is so?
      You've read in the entire file. The pointer is at the end of the file. Use seek to rewind. Or, if it's your intention to suck in the entire file anyway, do it on the first pass.
      I tried to use this $content = ` wc -l $Filehandle` but I could not get output in $count as it should be.
      Out of Define "did not work". What did you try? What did you get? What did you expect? Did you get an error? If so, what was it? What did you try to fix the error? you only answered the first question. Partially. $Filehandle sounds very fishy - is that a file handle, or does the variable $Filehandle actually contain the name of the file?
      This worked fine on command prompt bt not on browser.
      I give you one more chance: what did happen? Did you get an error? If so, which error? Check your error log as well. Or do you have some miracle wc which says, "Hmmm, I'm called by code written by Prafull. When he's running interactively I'm going to behave. But when it's run from a webserver, I'm going to return a random number!"?
        Hi JavaFan ,

        After using seek function , I could reuse File handle.
        I did not get anything from `wc -l `. I was expecting no of lines and name of file. This $FileHandle is a file handle only.
        I got following error when i used wc -l
        Tue May 11 11:45:17 2010 error client 192.168.1.101 sh: -c: line 0: `wc -l IO::File=GLOB(0xc7e51d0)', referer: http://1 Is the reason for this error is File handle. I was trying to read no of lines from file handle not file.
        What could be the solution for this ?

        Regards,
        Prafull