Brian Volk wrote:
> Hi All~

Hello,

> How can I grab the first item in every file and include in the first
> print statement below.  The first item will always start w/ a "$" and
> will not match a key in %DIR_LIST. The other items in the file (.pdf's)
> may or may not match a key in %DIR_LIST

It looks like you need something like this:

#!/usr/bin/perl
use strict;
use warnings;

# open the directory that contains all the MSDS in .pdf format
my $pdf_dir = '/var/www/html/msds';
opendir DIR, $pdf_dir or die "Can't open the $pdf_dir: $!\n";

# read file names in that directory into @pdfs
my @pdfs = grep /\.pdf\z/i, readdir DIR
    or die "Unable to read current dir:$!\n";
my %DIR_LIST = map { $_ => 1 } @pdfs;
closedir DIR;

# open all the .TXT file from the 400
my $orders_dir = '/home/bvolk/msds_in';
opendir ORDERS, $orders_dir or die "Can't open $orders_dir: $!";

# read all the item numbers in all the .txt files w/ map and
# load @ARGV for <> operator
@ARGV = map "$orders_dir/$_", grep !/^\./, readdir ORDERS;

my ( $job, $truck );
while ( <> ) {
    ( $job ) = $ARGV =~ /(\d+)/ if $. == 1;
    $truck = $1 if /\A\$(\d+)/;
    next unless /\A((.+)\.pdf)\z/;
    my ( $key, $msds ) = ( $1, $2 );

    if ( exists $DIR_LIST{ $key } ) {
        my $indy = 10;
        print "Job $job printing msds $msds to $indy on truck #$truck\n";
        }
    else {
        print "Job $job missing msds $msds\n";
        }
    }

__END__



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to