![]() |
|
Problems? Is your data what you think it is? | |
PerlMonks |
Re: Please help me with the outputby quester (Vicar) |
on Jan 14, 2012 at 06:39 UTC ( [id://947864]=note: print w/replies, xml ) | Need Help?? |
When run as-is, it says
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,
says
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 perlop. Fixing that, and fixing the spacing to make the function stand out better (the perltidy command from the Perl::Tidy module in CPAN can do it automatically, although it's overkill for these few lines) we get which prints
In Section
Seekers of Perl Wisdom
|
|