R
Robert Watkins
I've been away from Perl too long, folks, and I'm rusty.
Can't figure out how to declare a few dynamically generated names (i.e.
they could change with each run of the script) as "our" vars.
The idea is to use the names as filehandles, and to write to different
files based on what's found:
--------------------------------------------------------
our $name;
*name = *File::Find::name;
// this is the equivalent of what the script might see
// from the dynamic input:
my @statuses = ("New", "Updated", "Commented and Updated");
my $statuses = '(' . join("|", @statuses) . ')';
my $data;
my ($fh, $filename);
foreach $fh (@statuses) {
$us = $fh;
$us =~ s/\s+//g;
$filename = "blah.$us.list";
open($fh, ">$filename") or die "Could not create $filename: $!\n";
}
File::Find::find( {wanted => \&wanted, follow => 1}, CONTENT_DIR);
foreach $fh (@statuses) {
close($fh);
}
sub wanted
{
local $/;
my $data;
if (/^(sect0|withdrawal)-meta\.html\z/s) {
open(FH, "<$name") or warn "Can't open $name: $!\n";
$data = <FH>;
close(FH);
if ($data =~ /<meta name="unitStatus" content="($statuses)">/) {
$fh = $1;
print $fh "$name\n";
}
}
}
--------------------------------------------------------
Any suggestions?
Thanks,
-- Robert
Can't figure out how to declare a few dynamically generated names (i.e.
they could change with each run of the script) as "our" vars.
The idea is to use the names as filehandles, and to write to different
files based on what's found:
--------------------------------------------------------
our $name;
*name = *File::Find::name;
// this is the equivalent of what the script might see
// from the dynamic input:
my @statuses = ("New", "Updated", "Commented and Updated");
my $statuses = '(' . join("|", @statuses) . ')';
my $data;
my ($fh, $filename);
foreach $fh (@statuses) {
$us = $fh;
$us =~ s/\s+//g;
$filename = "blah.$us.list";
open($fh, ">$filename") or die "Could not create $filename: $!\n";
}
File::Find::find( {wanted => \&wanted, follow => 1}, CONTENT_DIR);
foreach $fh (@statuses) {
close($fh);
}
sub wanted
{
local $/;
my $data;
if (/^(sect0|withdrawal)-meta\.html\z/s) {
open(FH, "<$name") or warn "Can't open $name: $!\n";
$data = <FH>;
close(FH);
if ($data =~ /<meta name="unitStatus" content="($statuses)">/) {
$fh = $1;
print $fh "$name\n";
}
}
}
--------------------------------------------------------
Any suggestions?
Thanks,
-- Robert