I have a format declared in a regular script (yes, using strict). I will use it to generate a purchase order from an online listing of products. I originally put it in a class definition, but I kept getting errors like:
Global symbol "$city" requires explicit package name at lib/PurchaseOrder.pm line 192
So, it works flawlessly in the regular script, but it doesn't work at all in the method of this class. I want the method to generate the purchase order and save it to a database. It seems like there's no way to use strict and these formats at the same time in the class. At least, I can't figure out how to do it. The format declaration expects those variables to be globals. I have them declared with my() inside the method declaration, but that's not cutting it. Any ideas on how to get the format's expected variables to be "global" enough so the format can use them inside a class?
More for code, in case it's helpful.
Here's the code working in the script:
my ($sku, $description, $price, $qty);
foreach my $item (@items) {
($sku, $description, $price, $qty) = @$item;
write(PURCHASEORDER);
}
And of course it gets put into a sub when it gets dropped into the class, thus the issue with the globals.
Updated to fix formatting.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.