Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Update: can't believe I missed an important point. This is only if these are declared in a seperate block. D'oh.

my $x; if($test) { my $z; func(); } sub func { #cant see $z #can see $x since the sub is in the same scope as $x }

Mea Culpa.

1.Is there any difference between declaring variables at the beginning of scripts with my or our? Won't their scope be the same?
2.Is there a reason to use one or the other in this situation

1. The scope is the same. our variables cannot be used outside the current file (unless they are declared in the other file of course). In the file there is an important difference though. our variables can be seen in subroutines and my variables declared at the top of your script cannot be seen inside your subroutines. You must pass them in.

2. If you don't want your subs to see the variables without being passed in ( ie as global ) then you should use my.


In reply to Re: Our, use vars, and magic, oh my! by dga
in thread Our, use vars, and magic, oh my! by OzzyOsbourne

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 learning in the Monastery: (5)
As of 2024-03-29 13:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found