<?xml version="1.0" encoding="windows-1252"?>
<node id="947864" title="Re: Please help me with the output" created="2012-01-14 01:39:57" updated="2012-01-14 01:39:57">
<type id="11">
note</type>
<author id="576594">
quester</author>
<data>
<field name="doctext">
&lt;p&gt;
When run as-is, it says
&lt;/p&gt;
&lt;code&gt;
$ perl 947860.pl
Global symbol "$letter" requires explicit package name at 947860.pl line 5.
Global symbol "$letter" requires explicit package name at 947860.pl line 8.
Global symbol "$letter" requires explicit package name at 947860.pl line 10.
Execution of 947860.pl aborted due to compilation errors (#1)
    (F) You've said "use strict" or "use strict vars", which indicates
    that all variables must either be lexically scoped (using "my" or "state"),
    declared beforehand using "our", or explicitly qualified to say
    which package the global variable is in (using "::").

BEGIN not safe after errors--compilation aborted at /usr/lib/perl5/5.10/Carp/Heavy.pm line 11.
Compilation failed in require at /usr/lib/perl5/5.10/Carp.pm line 33.
&lt;/code&gt;
&lt;p&gt;
The errors relating to $letter and the diagnostic can be fixed with a "my $letter;" (our and state are more specialized, my is the most common way of declaring variables.)  Generally it is best to fix the first few obvious errors before worrying about less-obvious ones.  That's because Perl, like most compilers, can get confused enough by errors early in the program that it can't handle otherwise-valid code later in the program. So, fixing just the declaration of $letter,
&lt;/p&gt;
&lt;code&gt;
use strict;
use warnings;
use diagnostics;

my $letter  = 'b';
addtwo();
addtwo();
print $letter;
sub addtwo {
$letter +=2;
}
&lt;/code&gt;
&lt;p&gt;
says
&lt;/p&gt;
&lt;code&gt;
Argument "b" isn't numeric in addition (+) at 947860a.pl line 10 (#1)
    (W numeric) The indicated string was fed as an argument to an operator
    that expected a numeric value instead.  If you're fortunate the message
    will identify which operator was so unfortunate.

4
&lt;/code&gt;
&lt;p&gt;
Now, what is two more than "b"?  Well... it depends.  The interpretation that Perl took is to convert "b" to zero.  It might be that the "b" should have been a number, but my *guess* is that addtwo was meant to increment the letter twice, to get "d" after the first call and "f" after the second.  There is a way of doing that: "$letter++" will produce the next letter, because of some magic that applies only to the autoincrement "++" operator.  That magic doesn't apply to assignment operators such as "+=".  The details are in [http://perldoc.perl.org/perlop.html#Auto-increment-and-Auto-decrement|perlop].
&lt;/p&gt;
&lt;p&gt;
Fixing that, and fixing the spacing to make the function stand out better (the perltidy command from the [mod://Perl::Tidy] module in [cpan://] can do it automatically,  although it's overkill for these few lines) we get
&lt;/p&gt;
&lt;code&gt;
use strict;
use warnings;
use diagnostics;

my $letter = 'b';
addtwo();
addtwo();
print $letter;

sub addtwo {
    $letter++;
    $letter++;
}
&lt;/code&gt;
which prints
&lt;code&gt;
f
&lt;/code&gt;</field>
<field name="root_node">
947860</field>
<field name="parent_node">
947860</field>
</data>
</node>
