Here are some tips to read files:
This will read all the file too, but is a better way for big files:open (FILEHANDLE,"file.txt") ; @data = <FILEHANDLE> ; close (FILEHANDLE) ; chomp(@data); ## this will cut off the \n or \r ## in the end of each line.
open (FILEHANDLE,"file.txt") ; my $data ; 1 while( read(FILEHANDLE, $data , 1024*8 , length($data) ) ) ; close (FILEHANDLE) ;
This will read line by line:
open (FILEHANDLE,"file.txt") ; while ($line = <FILEHANDLE>) { ... } close (FILEHANDLE) ;
If you are trying to open binary files, use binmode() after open:
open (FILEHANDLE,"file.txt") ; binmode(FILEHANDLE) ;
In your code you tell that don't want to do $line = $line . $_ ;
This is not a good thing, because you rewrite all the variable for each loop, and is more slow. Do that:
You will find the same thing for:$line .= $_
See the site http://www.perldoc.com for more!$var += 10 ; # $var = $var + 10 ; $var -= 10 ; # $var = $var - 10 ; $var *= 10 ; # $var = $var * 10 ; $var /= 10 ; # $var = $var / 10 ;
Graciliano M. P.
"The creativity is the expression of the liberty".
In reply to Re: reading files
by gmpassos
in thread reading files
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |