aka_bk has asked for the wisdom of the Perl Monks concerning the following question:

Hello, i have a directory 'DAX' with pdf files: adidas Q4.pdf, puma Q1.pdf, nike Q3.pdf. I would like to process them one by one, but i'm having difficulties to call them by the second subroutine.

&open_dir('DAX', '/da/transcripts/DAX'); sub open_dir { $somedir=shift; $dirname=shift; opendir $somedir, $dirname or die 'Cannot open $dirname: $!'; while( $file = readdir $somedir) { print "$file\n" if -T "$dirname/$file"; &build_string($file); } } sub build_string { my $transcript=shift; use CAM::PDF; my $pdf = CAM::PDF->new($transcript); my $page_number=$pdf->numPages(); print "$page_number\n"; for (1..$page_number) { my $text=$pdf->getPageText($_); my $conc_text.=$text; print "$conc_text\n"; } }

What did i do wrong? Thanks in advance!

Replies are listed 'Best First'.
Re: Processing multiple pdfs using CAM::PDF
by GrandFather (Saint) on Nov 20, 2009 at 04:34 UTC

    What did you do wrong? Well:

    1. You didn't tell us what your difficulty is.
    2. You are using & to call subs.
    3. You are not using strictures (use strict; use warnings;).
    4. You don't check that CAM::PDF->new($transcript) succeeded.
    5. my $conc_text.=$text; is bizarre and unnecessary, just use $text in the following print.
    6. Placing use CAM::PDF in the middle of your code is misleading. use is parsed during the compilation phase so putting use anywhere except atthe top of your script gives a false impression of when it is executed.

    True laziness is hard work