B
banker123
I have the code below that opens a directory, determines the current
date and extracts the file names that start with the current date, then
loops through the contents of those files to extract data in a scalar
context.
Question
1. How do I sort the variables in a scalar context not an array?
Should I be reading the variables I have extracted into an array?
2. This program executes every 15 seconds to output the contents of
the directory. The output is used to control work flow and meet crucial
deadlines. Is this effeciently written? Any suggestions?
My first "production" perl program, after reading and learning perl for
about a month.
#Open directory
my $dir="G:/Formware/files/";
opendir DH, $dir or die "Cannot open$!";
#Get system date in the format mmddyy
@months = qw(01 02 03 04 05 06 07 08 09 10 11 12);
@days = qw(01 02 03 04 05 06 07 08 09 10..31);
($second, $minute, $hour, $dayOfMonth, $month, $yearOffset, $dayOfWeek,
$dayOfYear, $daylightSavings) = localtime();
$dayOfMonth=sprintf("%02d", $dayOfMonth);
$date = "$months[$month]$dayOfMonth06";
#Read each file beginning with system date from directory
@files=grep(/^$date/,readdir(DH));
closedir (DH);
foreach $file (@files) {
open (data, "$dir$file") or die "Cannot open file: $!";
while ( <data> ) {
if ( /JOBNAME/ ) {
$job = substr($_,8,8);
chomp($job);
}
elsif ( /\.TIF\s{12}/ ) {
my $box = substr($_,73,6);
printf "$box $job $file\n";
last;
}
}}
date and extracts the file names that start with the current date, then
loops through the contents of those files to extract data in a scalar
context.
Question
1. How do I sort the variables in a scalar context not an array?
Should I be reading the variables I have extracted into an array?
2. This program executes every 15 seconds to output the contents of
the directory. The output is used to control work flow and meet crucial
deadlines. Is this effeciently written? Any suggestions?
My first "production" perl program, after reading and learning perl for
about a month.
#Open directory
my $dir="G:/Formware/files/";
opendir DH, $dir or die "Cannot open$!";
#Get system date in the format mmddyy
@months = qw(01 02 03 04 05 06 07 08 09 10 11 12);
@days = qw(01 02 03 04 05 06 07 08 09 10..31);
($second, $minute, $hour, $dayOfMonth, $month, $yearOffset, $dayOfWeek,
$dayOfYear, $daylightSavings) = localtime();
$dayOfMonth=sprintf("%02d", $dayOfMonth);
$date = "$months[$month]$dayOfMonth06";
#Read each file beginning with system date from directory
@files=grep(/^$date/,readdir(DH));
closedir (DH);
foreach $file (@files) {
open (data, "$dir$file") or die "Cannot open file: $!";
while ( <data> ) {
if ( /JOBNAME/ ) {
$job = substr($_,8,8);
chomp($job);
}
elsif ( /\.TIF\s{12}/ ) {
my $box = substr($_,73,6);
printf "$box $job $file\n";
last;
}
}}