Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
It seems you are completely correct. I was under the distinct assumption that defining a variable in a scope (aka declaring) trough the use of our, lifted that variable out of the scope and accesible for other scopes. This seems only trough when using no strict 'vars' (but that would not be nice).

<off-topic>
  Does it matter whetter we call 'this' defining or declaring? I know the difference between the two, and if you are a nice perl -wT && strict programmer you define and declare all at once, to prevent warnings.
</off-topic>

Your snippet leads to the suspicion that more evil-hack's are possible with perl, then I so far realized.
I off course tested your snippet, and it works prima!
However if you would add these lines:
package not_main; { print $foo; print $main::foo; print "\n"; } package main;
It would _still_ work fine. This puzzles me. (Why one would define more packages inside one script puzzles me as well)

As you I was somewhat confinced that I knew the language and the behavior of the interpreter by now. This has once again proofed me wrong, and that is what keeps perl interesting!

And then, last but not least: thnx 4 ur reply ;-)

A righthanded-lefthand....
"Field experience is something you don't get until just after you need it."

In reply to Re: Re: Re: Help needed understanding global variables in Perl by Sinister
in thread Help needed understanding global variables in Perl by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2024-04-19 05:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found