1829108 Members
13260 Online
109986 Solutions
New Discussion

Ghost in a PERL script

 
Enrico Venturi
Super Advisor

Ghost in a PERL script

Hello colleagues

I'm running a simple PERL program which lists a directory content, then analyze each item of the directory, then lists again, and so on.
SOmetimes the lists loopbacks on itself.
See the program branch ...

system("ls -rt $buffer/*.ToBeCopied > $buffer/TBC 2>/dev/null");
if ( -T "$buffer/TBC" && -s "$buffer/TBC" ) {
open (FILE_LIST, "$buffer/TBC");
while (my $filename= ) {
print "process $$: processing $filename\n";
}
...
There's a KSH script which is populating the directory.
It seems that the "$filename= " doesn't increment the file handler, or at a certain point the condition doesn't return "NULL" but it starts again from the beginning ....

any helps?

thanks
Enrico
5 REPLIES 5
Steven E. Protter
Exalted Contributor

Re: Ghost in a PERL script

Add this to your code:

$n1 = 0;

# your code
# Additional while condition
while($n1 eq 0){;



if(eof(FILE_LIST)){ $n1 = 1 } ;
};


This way when you detect eof, end of file in your reading of the file list your program can terminate.

Good Luck,

SEP


Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Enrico Venturi
Super Advisor

Re: Ghost in a PERL script

Nothing changed :-(

it seems EOF never detected.......
Gregory Fruth
Esteemed Contributor

Re: Ghost in a PERL script

I don't know why you're seeing the errors;
however, you'd be better off using some of
Perl's built in operators instead of doing
a system("ls ...") and reading in the file:

opendir(DIR, $buffer);
@files = sort(readdir(DIR));
closedir(DIR);
foreach $file (@files) {
$filename = "$buffer/$file";
next unless -T $filename;
next unless -s $filename;
next unless $filename =~ /\.ToBeCopied$/;
print "process $$: processing $filename\n";
...
}
Ganesha Sridhara
Honored Contributor

Re: Ghost in a PERL script

Hi Enrico,

I have attached sample perl file to list directory recursively.
Please change your $root_dir variable.

Regards
Ganesha Sridhara

Enrico Venturi
Super Advisor

Re: Ghost in a PERL script

I changed my code, now it works.