Hello Monks, first time posting. I am trying to convert thousands of HTML files to a single PDF using wkhtmltopdf (called through a Perl script); this works via the Windows 7 command line like so:

wkhtmltopdf file1.htm file2.htm output.pdf

My issue is that the command line reaches its character limit when I try to add my string of file names as an argument. My workaround so far is to split the string into ~5000 character sections, which works when typed out literally like so:

my $result = `wkhtmltopdf.exe $lists[0] $lists[1] $lists[2] $project.pdf`;

However, since the number of HTML files varies from project to project, I cannot hard code the $list indexes, since @lists could have any number of indexes. I have tried working around this using a for-loop to created a string like so:

# Split up master list into smaller strings so that command line l +imit is not reached (limit to around 5000 chars) my @lists = $masterList =~ /(.{5000,}? )/g; # build the string of filename groups for pdf conversion my $htmlFiles = ""; for (my $y = 0; $y < $#lists; $y++) { $htmlFiles.= "\$lists[$y] "; }

I then make the system call with backticks like so:

    my $result = `wkhtmltopdf.exe $htmlFiles $project.pdf`;

This creates a small empty pdf, giving no errors. I know the issue (I think)... the backticks make Perl replace $htmlFiles with the string $htmlFiles, but once that replacement is made, the string contents do not get interpolated (ie. $lists[0] remains $lists[0] and not the contents of the first index of @lists).

Since I am relatively new to Perl (2 months in), I'm lost and searching for solutions has been difficult. If Perl cannot perform these multi-level interpolations, can someone suggest a solution?


Thank you, Colin


In reply to Interpolating string that contains variables to be interpolated by fpscolin

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.