Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Globals with Strict

by cchampion (Curate)
on Sep 12, 2003 at 15:06 UTC ( #291082=note: print w/ replies, xml ) Need Help??


in reply to Globals with Strict

Others have told you to declare the shared variable at the top of the file. Here's why:

#!/usr/bin/perl use warnings; use strict; x(); # this will trigger a warning my $shared = 'abc'; sub x { print "\$shared is: <$shared>\n"; } x(); # this will work fine

Although $shared is within the same scope as the sub x, its value has not yet been initialized. Therefore, the first time you call the subroutine, you get a warning for using an uninitialized value. Once the program flow passes over the shared point, everything it's OK. That was why, if you need a shared value, it should be "at the top".

HTH


Comment on Re: Globals with Strict
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (16)
As of 2014-11-25 21:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (158 votes), past polls