in reply to Help with efficiency

It's not clear to me what your problem is. Is your problem that you currently have just one $im, but want more? In that case, you should probably use an array. Or is your problem that you have to write to multiple files? In that case, instead of writing to STDOUT, open one or more files yourself (using the open function) and write to the filehandles using print.

Abigail

Replies are listed 'Best First'.
Re: Re: Help with efficiency
by stu96art (Scribe) on May 13, 2004 at 01:25 UTC
    My problem is that I have an unknown number of "sheets" or objects that I am trying to create. I want to create different graphic files for each object. What I am using now works, but I use the command prompt to tell the object information where to go, graphics.pl > im.png . I do not know how to adjust where the object information will go to so that it can change with different objects. Thanks for your help
      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

      Well, just as I said, open the files you want to write to in your program, and write to them.

      Abigail