Hi,
I am trying to know more about POE following the Matt Sergeant's
excellent slides from the location
http://axkit.org/docs/presentations/tpc2002/poe.pdf
I modified the example on slide 284 to this below and it seems to work fine
deleting the files in the folders sent as command-line arguments.
# =======================================
use strict;
use warnings;
use POE;
$|++;
POE::Session->create(
inline_states => {
_start => \&process_file,
process_file => \&process_file,
},
args => [ @ARGV ],
);
$poe_kernel->run();
exit(0);
sub process_file {
my ($kernel, $heap, @dirs) = @_[KERNEL, HEAP, ARG0..$#_];
my $file;
DIRECTORY:
foreach my $dir (@dirs) {
opendir(DIR, $dir) || die "Can't open dir $dir: $!";
while (my $filename = readdir(DIR)) {
$filename = "$dir\\$filename";
if (-f $filename) {
$file = $filename;
last DIRECTORY;
}
}
closedir(DIR);
}
if ($file) {
do_something_with_file($file); # this deletes $file
$kernel->yield('process_file', @dirs);
}
# hint: we forgot something here
}
sub do_something_with_file {
my ($file) = @_;
print "file = $file\n";
unlink($file);
}
# =======================================
Question:
I am not sure what Matt referred to as that we forgot at the end of the
sub-routine process_file(). The script above executes and runs to completion
deleting all the files in the directory without any problem. Can someone please
help me understand what I am missing here.
Thanks in advance.
---------------------------------
Do you Yahoo!?
Everyone is raving about the all-new Yahoo! Mail Beta.