[boulder.pm] Forwarded: "Non-member submission" fromlynn.danielson@clue.denver.co.us

Walter Pienciak walter at frii.com
Fri Nov 9 14:33:04 CST 2001


Sender: lynnd at ihs.com
Message-ID: <3BEC1913.18AC43AF at clue.denver.co.us>
Date: Fri, 09 Nov 2001 10:57:39 -0700
From: Lynn Danielson <lynn.danielson at clue.denver.co.us>
Organization: Colorado Linux Users & Enthusiast
X-Mailer: Mozilla 4.76 [en] (X11; U; SunOS 5.7 i86pc)
X-Accept-Language: en
MIME-Version: 1.0
To: boulder-pm-list at happyfunball.pm.org
Subject: piped output filehandle in loop problem
References: <5FE9B713CCCDD311A03400508B8B30130AB7FC6D at bdr-xcln.corp.matchlogic.com>
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit
X-ECS-MailScanner: Found to be clean

I want to loop through a directory of pdf files, run a shell
command (pdfinfo) on each file, and grep the command output to
see whether the pdf file is encrypted.

Derek Noonan's pdfinfo command produces 11 lines of output like
the following:

Title:
Subject:
Keywords:
Author:       Marion Wilkinson
Creator:      C:MARGIEAMDTS¦88.AM1
Producer:     PDF Prep Tool (www.glance.ch)
CreationDate: 19970701095714
ModDate:      20011108101825
Pages:        1
Encrypted:    no
Linearized:   yes

The 10th line of output specifies if the file is encrypted.
So, I tried this ...

#!/usr/local/bin/perl -w

$pdfdir = "/path/to/pdf/files";
opendir(INPUT, $pdfdir) or die "Couldn't open directory: $pdfdir";

while (defined($file = readdir(INPUT))) {
    next if $file =~ /^\.\.?$/; # skip . and ..
    open(PDFINFO, "pdfinfo $inputdir/$file |") or die "Can't fork: $!";
    print "$file is encrypted\n" if ( (<PDFINFO>)[9] =~ m/ yes / );
    close(PDFINFO);
}

closedir(INPUT);

It works for the first file, but every iteration thereafter gives me
an "uninitialized value in pattern match" error.  Why?  Suggestions?

Thanks,

Lynn Danielson




More information about the Boulder-pm mailing list