Hi All~

 

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

 

 

Filename1: O20270.TXT

$432

12345.pdf

12121.pdf

 

Filename2: O20271.TXT

$433

12345.pdf

12000.pdf

 

 

 

#!/usr/bin/perl 

 

use strict;

use warnings;

use File::Basename;

 

 

# 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 = readdir(DIR) or die "Unable to read current dir:$!\n";

 

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 %DIR_LIST;

 

 $DIR_LIST{$_} = 1 for @pdfs;

 

while (<>) {

              chomp;

              $_ =~ s/\s+\z//;

 

            # I tried to shift off the first item here w/ $my truck =
shift; but I was shifting off the first file..

            # plus it will be out of scope when I try to print. 

                        

            if(exists($DIR_LIST{$_})){ # the first item in each file
will not exist but I want to grab it and

                                                  # assign it to my
$truck. 

 

 

            my   $basename = fileparse($ARGV,'.TXT');

              $basename =~ s/O//;

              $_ =~ s/.pdf//i;

              my $indy = 10;

 

          print "Job $basename printing msds $_ to $indy on truck #
$truck \n";

 

          } else {

          

my $basename = fileparse($ARGV,'.TXT');

          $basename =~ s/O//;

          print "Job $basename missing  msds $_\n";

}

 

 Thanks for any suggestions!

 

Brian 

 

Reply via email to