Change this below line as shown: from open my $WFH, '>', $clusterservice_info to open my $WFH, '>>', $clusterservice_info
As you have open the file in write mode, the file will be overwritten by each execution. Instead if you use append mode, the information will be appended to the same file. Regards, Ganesh On Thu, May 21, 2009 at 11:56 PM, Anirban Adhikary <anirban.adhik...@gmail.com> wrote: > Hi List > The below mentioned code will run at the same time ( symaltaneously) from 2 > or more separate locations and it will write its execution(absolute path) > path and its PID. > But when ever I am trying to run this code only one program's information is > written to the common file and other program's information is not being > written.I have tried a lot to rectify this problem but not able to > understand why this is happening.Also tell me where I am making the mistake. > > Please help me to solve this problem > > > my ( $scriptname, $home ) = File::Basename::fileparse( realpath($0) ); > > my $progname_abs_path = "$home$scriptname"; > > my $clusterservice_info = > "/home/merge/testcode/cluster/sharedbox/cluster_service_status.txt"; > > if ( ! -s $clusterservice_info ) { > > open my $WFH, '>', $clusterservice_info > > or die "Cant'open $clusterservice_info $! \n" ; > > flock( $WFH,2); > > print $WFH "$progname_abs_path:-:$$\n"; > > close($WFH); > > } > > else { > > open my $WFH1, '+<', $clusterservice_info > > or die "Cant'open $clusterservice_info $! \n"; > > flock( $WFH1,2); > > while (my $line = <$WFH1>) { > > chomp $line; > > next if $line =~ /^$/; > > my($firstval,$secondval) = $line =~ /^(.*?):-:(.*?)$/; > > print "firstval = $firstval \n"; > > if ($firstval ne /^$progname_abs_path$/) { > > seek($WFH1, 0, 2); > > print $WFH1 "$progname_abs_path:-:$$\n"; > > } > > } > > close($WFH1); > > } > > > > Thanks & Regards > > Anirban Adhikary > -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/