in reply to Re: Trouble with an array inside a format call
in thread Trouble with an array inside a format call

Thanks for the help first of all, also Marshall I like the way you have done it on your third suggestion and I was wondering if with it like that would #2 still be a problem?
As for 4 format does its job and I can't argue with that, but my goal is to that the program is to have the program write format and its output to the /tmp/repairs file.

  • Comment on Re^2: Trouble with an array inside a format call

Replies are listed 'Best First'.
Re^3: Trouble with an array inside a format call
by Marshall (Canon) on Oct 17, 2009 at 06:35 UTC
    I see that I inadvertently used #3 twice but, Yes, re-doing the command loop will solve the problem in #2.

    If you mean the DB authentication, I would authenticate early and this "my $dbh" (database handle) will have package scope, a my $var at the top package level which cannot be exported to other modules (because it is a "my"), but yet would be visible to any sub in the package.

    Even that you don't need to pass this to subs, I would pass the $dbh as a param to each "action" sub that needs it. The reason for that is to make it clear what each sub is using. You should wind up with a very small number of package level "real" variables. To further that I would suggest using the "constant" pragma.

    use constant database => "Repairs"; #the database name use constant hostname => "192.168.1.111"; #MySQL server IP address use constant port => '3306'; #MySQL port
    A constant is not a $variable and cannot be modified. You use it like a bareword (without any $ in front of it) in the actual code. I recommend this for package level things that are the "seldom changed, but important constants that might need to change in a different version of the program".

    You should wind up with a very small number of package scoped "real variables" that the program changes during execution.

    As far as Perl FORMAT goes, you will have to make up your mind about that as you write more code. It appears to work fine for strings, but when you want say exactly 2 decimal places for a currency number, this is not so good.

    BTW, for this heading thing, there is no need for a FORMAT statement. A simple way is to use what is called a "here is" document.

    #!/usr/bin/perl -w use strict; my $STDOUT_TOP= <<END_TOP; ID First Name Last Name Email Address Phone Number Dat +e Comp. Manufacturer Comp. Model Model Number OS ========== ========== ============ ================ ============ === + ======= ================== =========== ============ ============= END_TOP print $STDOUT_TOP;

      My goal with this is get it so It will have formatted output that is set to a temporary file for printing. When it is done and the page is printed I want the page to look like what my current format is, where there is a header saying what each field is and then the customer/computer info and everything lines up when it is done.

      If this is something that is better and easier done with printf/sprintf then that is fine with me.