Hi All,
My requirement is, I want to remove first and last line of a text file.
I did it like,
###################################################
open READ_FILE ; # This is file I am reading
open WRITE_FILE ; # This is file I am writting
$cur_lino = 0 ;
$prev_lino = 0 ;
$prev_line = "" ;
while (<READ_FILE>)
{
$cur_lino ++ ;
if ( $prev_lino > 1 )
{ print WRITE_FILE $prev_line ; }
$prev_line = $_ ;
$prev_lino ++ ;
}
close READ_FILE ;
close WRITE_FILE ;
###################################################
This works.
But, is there a better way to do this? any ready utility?command?
Also, I am on Unix, but do not want to use shell commands in perl i.e. $var1 = `wc -l $filename`. Don't want to do this.
Thanks in advance.
My requirement is, I want to remove first and last line of a text file.
I did it like,
###################################################
open READ_FILE ; # This is file I am reading
open WRITE_FILE ; # This is file I am writting
$cur_lino = 0 ;
$prev_lino = 0 ;
$prev_line = "" ;
while (<READ_FILE>)
{
$cur_lino ++ ;
if ( $prev_lino > 1 )
{ print WRITE_FILE $prev_line ; }
$prev_line = $_ ;
$prev_lino ++ ;
}
close READ_FILE ;
close WRITE_FILE ;
###################################################
This works.
But, is there a better way to do this? any ready utility?command?
Also, I am on Unix, but do not want to use shell commands in perl i.e. $var1 = `wc -l $filename`. Don't want to do this.
Thanks in advance.