On Friday 02 November 2007 03:30, sivasakthi wrote:
> Hi all,
Hello,
> In my script doing the following requirement,
>
> I need to check one temporary file , that file contains the position
> of the file handle
>
> if the temporary file is not present then open "abc" file and read
> the datas for some calculation after that update the last line
> position to the temporary file
So far so good.
> suppose the temporary is present then need to seek the already stored
> file position from "abc" file , if the that position is not catched
> in "abc" file then will continue the seeking process from "abc.0", if
> also not catched then seeking from "abc.1" .... this is up to
> "abc.10"
What do you mean by "catched" (cached perhaps?) How do you determine
if the position is "catched" in a particular file?
> once if the already stored file position is catched then store that
> filename up to "abc" in to one array.
>
> for example if the file position is catched in "abc.3" then need to
> push the following information in to array,
> abc.3 abc.2 abc.1 abc.0 abc
>
> the started script is shown below,
>
> #! /usr/bin/perl
>
> use warnings;
> use strict;
>
> if ( ! -e "tmp.txt")
> {
> open FF, "abc" || die "can't open abc file\n";
Because of the high precedence of the '||' operator that will *never*
die. You need to either use parentheses:
open( FF, "abc" ) || die "can't open abc file\n";
Or use the lower precedence 'or' operator:
open FF, "abc" or die "can't open abc file\n";
You should include the $! variable in the error message so you know
*why* open failed.
> while (<FF>)
> {
> chomp;
> #some calculation
> }
> my $pp=tell(FF);
> open FP, "> tmp.txt" || die "can't open the tmp file\n";
See above.
> print FP $pp;
> close FP;
> close FF;
> }
> else
> {
> open FF,"tmp.txt" || die "can't open the file\n";
See above.
> while(<FF>)
> {
> chomp;
> my $pp=$_;
> }
> # need to check , but have some trouble of from which file to start
> and forming the array
>
> }
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/