in reply to Best Practice for Replacing Globals

G'day beaker121,

Welcome to the Monastery.

You'll need to show us the code where these global variables are defined; or, at least, a small extract of that code such that we can understand what is going on. Your prosaic description is unclear. Your posted code does not reference any global variables.

[Aside: I appreciate that this is your first post, so you probably didn't know about this, but please see "What shortcuts can I use for linking to other information?". As an example, writing vars::global, instead of just vars::global, makes referencing modules you're discussing a lot easier.]

By the way, "return $self->{$name} || '';" looks dodgy. If the actual value was zero, did you really want to report it as a zero-length string. I don't know enough about your code, but suspect exists() and/or defined() might be useful here.

— Ken

Replies are listed 'Best First'.
Re^2: Best Practice for Replacing Globals
by LanX (Saint) on Apr 19, 2023 at 22:02 UTC
    > As an example, writing vars::global

    Oh I wasn't aware this is an actual CPAN module ... thanks! :)

    All lowercase is a strange naming decision, though.

    Cheers Rolf
    (addicted to the 𐍀𐌴𐍂𐌻 Programming Language :)
    Wikisyntax for the Monastery