The thing you are missing is do you really need to use $xyz outside of the scope of the subroutine. I would read up on variable scope in the Llama book and/or the Camel book. Basically, you can substitute the following:
&example(15);
sub example {
my($xyz) = shift || 0;
my($a) = $xyz + 49;
print $xyz;
print $a
}
After doing this, $a and $xyz won't be available to you outside of the subroutine. This is all assuming you're operating under strict. Really, you ought to read the Llama book if nothing else, it's fantastic information and explains a lot of this much more clearly than I can. =] -marius
-
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.
|