1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 #
7 # Better Ways to do things
8 my @colors = qw( red green blue yellow orange );
9 print join(', ', @colors), "\n";
10
11 my $alphabet = 'abcdefghijklmnopqrstuvwxyz';
12 my @letters = split('', $alphabet);
13 print join(', ', @letters), "\n";
14
15 #---------------------------------------------------------#
16 print "\n";
17 #---------------------------------------------------------#
18
19
20 #
21 # Looping with Arrays
22 #---------------------------------------------------------#
23 print "C Style Loops\n";
24 #---------------------------------------------------------#
25 for( my $i = 0; $i <= $#colors; $i++ ) {
26 print " Current Color: $colors[$i]\n";
27 }
28
29 #---------------------------------------------------------#
30 print "Perl Style Loops\n";
31 #---------------------------------------------------------#
32 foreach my $color ( @colors ) {
33 print " Current Color: $color\n";
34 }
syntax highlighted by Code2HTML, v. 0.9.1