in reply to For Statement & Letters

Rather than using using C-Style for loops, you should probably use Foreach Loops both described in perlsyn. For the numbers case you have given and using Range Operators as described in perlop to generate the list, you could replace:

my $start_number = 1; my $end_number = 10; for (my $i=$start_number; $i<=$end_number; $i++) { print "\$i = $i\n"; }

with the much briefer, clearer (IMHO) and more robust (less prone to bugs):

foreach my $i (1 .. 10) { print "\$i = $i\n"; }

One of the nice features of range operator is that it operates on letters as well as numbers:

foreach my $i ('A' .. 'D') { print "\$i = $i\n"; }

Perl documentation seems to be down right now, so hopefully the above links function properly, but if not, you should be able to use the above information to navigate your local copies of the documentation. As a side note, see Writeup Formatting Tips, in particular please wrap posted code in <code> tags to aid in readability.

Replies are listed 'Best First'.
Re^2: For Statement & Letters
by dsheroh (Monsignor) on Jan 28, 2010 at 08:26 UTC
    Just one minor note to add: In Perl, foreach is just an alternate spelling of for. This can also be written as (and I would write it as) for my $i ('A' .. 'D')