Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: format declaration in a class

by broquaint (Abbot)
on May 25, 2004 at 02:39 UTC ( #356103=note: print w/ replies, xml ) Need Help??


in reply to format declaration in a class

Declare your format variables with either vars or our and then within the loop use local e.g

use vars qw($sku, $description, $price, $qty); foreach my $item (@items) { local($sku, $description, $price, $qty) = @$item; write(PURCHASEORDER); }
Or you could fully qualify your variables in your format and localize the appropriate variables i.e
use strict; format STDOUT = @<<<<<<< $::foo . local $::foo = 'a string'; write STDOUT; __output__ a string
Or you can declare the lexicals before the format, if that's feasible. See. perlform for more info.
HTH

_________
broquaint

update: added second to last sentence and finished the incomplete middle sentence


Comment on Re: format declaration in a class
Select or Download Code
Re: Re: format declaration in a class
by saberworks (Curate) on May 25, 2004 at 04:06 UTC
    Hi and thanks for your help. The use vars seems to work fine, although when I tried our (in fact I tried it first before I posted to perlmonks.org), I got (and continue to get) these errors:

    Variable "$sku" is not imported at lib/PurchaseOrder.pm line 206
    Global symbol "$sku" requires explicit package name at lib/PurchaseOrder.pm line 206.


    So my only solution (I guess?) is to use vars.
    I'm going to do more research to figure out exactly what that does. Thanks a lot! Update: Well I was mistaken, I need to put the our declarations external to a sub. In which case it works perfectly. Thanks again!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2014-07-26 17:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (178 votes), past polls