Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re: Perl Riddle

by Somni (Friar)
on Dec 01, 2007 at 10:35 UTC ( #654302=note: print w/replies, xml ) Need Help??

in reply to Perl Riddle

It's really hard to pin down what your problem might be because you're not actually showing any of the code that calls these functions. I'd guess that the problem is you just aren't initializing %ENGINES before you start calling subroutines that use it.

Your use of strict and our is broken, however. Because they are both in a BEGIN block the scope of both is confined to just that block, making them essentially useless.

It's best to have use strict (and probably a use warnings) at the top of your code, outside of any block. The declaration for %ENGINES could be at the top, if you like, but I prefer to have the 'our' declaration near where I actually use the variable. If you intend to initialize %ENGINES at module startup then putting the declaration in a block can be a good idea.

package Data::CryptRecord; use warnings; use strict; { our %ENGINES = (...); } sub set_engine { my($self, $name) = @_; our %ENGINES; ... }

This provides some self-documentation; it's clear that %ENGINES is global. You can also initialize %ENGINES outside a block, and not have to declare it in your subroutines.

Log In?

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2023-11-30 23:02 GMT
Find Nodes?
    Voting Booth?

    No recent polls found