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!"?
| [reply] [d/l] [select] |
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
| [reply] |
| [reply] [d/l] |