Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: how do i create a global var conditionally?

by rizzo (Curate)
on Mar 02, 2018 at 15:19 UTC ( [id://1210235]=note: print w/replies, xml ) Need Help??


in reply to how do i create a global var conditionally?

Not shure if I get the point here, but it is possible if the global you want to create will be part of an existing array or hash.
use strict; use warnings; my @globalarray; my $gatekeeper = 1; if($gatekeeper) { push @globalarray, 'foo'; # creates $globalarray[0] } print "$globalarray[0]\n";

Replies are listed 'Best First'.
Re^2: how do i create a global var conditionally?
by AnomalousMonk (Archbishop) on Mar 02, 2018 at 16:07 UTC
    ... the global you want to create ...

    But be aware that  my @globalarray; still declares a lexical variable: it is not visible to any code prior to the point of declaration, and it is not visible in any other source file in the application. If a lexical is declared very early in a source file (update: and if it's not declared in a block scope of any kind, i.e., if it's "in file scope") and if there is only one source file in the application, then a lexical can give a pretty darn good imitation of a global, but it's still a lexical.


    Give a man a fish:  <%-{-{-{-<

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-04-24 08:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found