Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Re^3: PDF::Create Questions

by peppiv (Curate)
on Apr 09, 2003 at 12:43 UTC ( [id://249207]=note: print w/replies, xml ) Need Help??


in reply to Re^3: PDF::Create Questions
in thread PDF::Create Questions

I can't seem to get it right. I understand using the '>' to open a file to overwrite, but no matter how I try to make the syntax work, I fail.

How do I get from here

my $fh = new FileHandle "> $self->{'filename'}";
to here?

my $pdf = new PDF::Create ('filename' => '/html/mypdf.pdf', 'PageMode' => 'UseNone', );
Even trying this
my $pdf = new PDF::Create "> ('filename' => '/html/mypdf.pdf', 'PageMode' => 'UseNone', )";
and giving the pdf file 777 permissions doesn't work. Please help!

peppiv

Replies are listed 'Best First'.
Re^5: PDF::Create Questions
by tall_man (Parson) on Apr 09, 2003 at 15:08 UTC
    You are not being specific about what you mean by "I fail" and "it doesn't work." What's the error message?

    Using the sample.pl file that came with the PDF::Create module, I was able to overwrite an existing pdf file with no problem at all. I can't imagine what is going wrong unless there is something strange about "/html"... Try creating and overwriting in a local directory instead.

      My apologies. I let my frustration get the better of me sometimes. Appreciate the patience.

      I can easily create a file using this:
      my $pdf = new PDF::Create ('filename' => '../html/logs/mypdf.pdf', 'PageMode' => 'UseNone', 'Title' => 'Anything', );
      If I use this:
      my $pdf = new PDF::Create "> ('filename' => '../html/logs/mypdf.pdf', 'PageMode' => 'UseNone', 'Title' => 'Anything', )";
      It doesn't create a pdf. And it doesn't overwrite the existing one. I tried using a local directory and it made no difference.

      This is the error message I get when I run the second piece of code.

      Odd number of elements in hash assignment at /usr/lib/perl5/site_perl/5.6.1/PDF/Create.pm line 28.

      When I placed the '>' symbol in different parts of the line I would get 'syntax error in line ...... around '>'.."

      I know I'm missing something small here, and I just can't seem to find it. Any ideas are welcome. (Except "don't quit your day job"!) I like learning Perl!

      peppiv

        You are not understanding what the lines of code are going to do. You're trying to randomly come to a solution that will work long enough for you to tell your manager the problem is solved. While this problem-solving method has merit, especially if you're not a programmer by trade, it most definitely ... lacks completeness.

        First, you have to stop writing code. Yes, this means that you need to step away from the computer.

        Next, take a minute and actually attempt to understand what you're trying to do. Write it out on paper or a whiteboard or something. Lay out every single step, both in terms of business logic and then translate those business steps into programming steps. There will be a N to M relationship between them.

        At this point, look at the tools you have (PDF::Create, for example) and see what the documentation says for how to do something. If there is a language construct you don't understand (like Perl OO, for example), pick up a copy of an appropriate book (Damian's OO Perl or the Camel book) and learn the necessary language features.

        Now, at this point AND ONLY THIS POINT are you ready to actually write any code. Not only will you know what you want to write, but you'll also know how to write it. Syntax errors will become a thing of the past (other than typos).

        If this sounds like overkill - that's because this is repeatable, provable applications development. Not HaX0r1SiNg.

        ------
        We are the carpenters and bricklayers of the Information Age.

        Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.

        Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.

        Your first block of code is correct, and it will overwrite the old file automatically. That's all there is to it.

        You are scaring me with your creative uses of ">", and now I wish I had never shown you that line. As I keep trying to tell you, the "new PDF::Create" call does that for itself.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://249207]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (6)
As of 2024-04-19 15:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found