Hey Thanks uri!!! Actually i have a global variable which contains information of all files and their size
you have given great directions Thanks all of you!! Regards a b On Fri, May 20, 2011 at 9:39 PM, Uri Guttman <u...@stemsystems.com> wrote: > >>>>> "ab" == a b <testa...@gmail.com> writes: > > ab> Hey Thanks all! > ab> I got it ;) > > ab> open (FH, "+< $fname")|| die "\nFailed to open file $fname\n"; > > you don't need to open the file at all. truncate can take a filename. ab> my $tmp=$fsize-$trunccount; > > where do those get set? don't name vars $tmp as that tells the reader > nothing about the variable's use. > > ab> seek(FH,$tmp,0); > ab> $addr = tell(FH) ; > > you don't need the seek and tell calls. you have the size you want and > you can pass that directly to truncate. > > > ab> truncate(FH, $addr)|| die "\nFailed to truncate $file: $!"; > ab> close(fd); > ab> print "\nTruncate successful\n"; > > > this can all be reduced to this: > > my $size = -s $file ; > truncate( $file, $size - $truncount ) || > die "\nFailed to truncate $file: $!"; > > uri > > -- > Uri Guttman ------ u...@stemsystems.com -------- http://www.sysarch.com-- > ----- Perl Code Review , Architecture, Development, Training, Support > ------ > --------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com--------- >