What I am using now works, but I use the command prompt to tell the object information where to go, graphics.pl > im.png
Instead of printing your single object to STDOUT, you'll need to print out each object inside your code.

This will result in code roughly like the following:

use strict; use warnings; my $i = 1; # The object number we're up to # create object 1 somehow open(FILE, ">", "object$i.png") or die "Failed to open object$i.png: $ +!"; # make sure we are writing to a binary stream binmode FILE; # Convert the image to PNG and print it to file print FILE $im->png; $i++; # create object 2 somehow, rinse and repeat
You may put all of that in a loop, or you may create an output subroutine, you may even choose to do all the printing at the end... But you're going to need to do the printing to files inside your program rather than capturing STDOUT and redirecting that to a file.

Keep in mind that using open with > will result in any previous data in the file called "object$i.png" to be overwritten. You can use the following test if this might be a problem:

my $filename = "object$i.jpg"; if(-e $filename) { die "$filename already exists in this directory\n"; # or something more useful. } open(FILE, ">", $filename) or die "Failed to open $filename: $!";

I hope this helps

jarich


In reply to Re: Re: Re: Help with efficiency by jarich
in thread Help with efficiency by stu96art

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.