On Tue, 30 Mar 2010 23:05:00 -0600
Jon Forsyth <jon4s...@gmail.com> wrote:

> I am truly a beginner.  Could someone help me understand this syntax
> out of a code example from "Learning Perl"?  On line 5 I'm confused
> as to why "my $number" is between "foreach" and the ()?  is "my
> $number part of the loop?

Yes, it is.  $number is the iteration variable and it is linked to each
element of the array in turn.  Changing $number will change the
contents of the array.

For example:
#!/usr/bin/perl

use strict;
use warnings;

my @array = ( 'a' .. 'z' );
print "before for loop: @array\n";

for my $item ( @array ){
  if( $item =~ /[aeiou]/ ){  # if a vowel
    $item = uc $item;        # make it uppercase
  }
}
print "after for loop: @array\n";

__END__


-- 
Just my 0.00000002 million dollars worth,
  Shawn

Programming is as much about organization and communication
as it is about coding.

I like Perl; it's the only language where you can bless your
thingy.

Eliminate software piracy:  use only FLOSS.

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to