Help for this page

Select Code to Download


  1. or download this
    foreach my $city ( @myCities ) {
       # $city is local to this loop only!
    }
    
    print "$city";  #there's no $city in scope!
    
  2. or download this
    my $city;  # now is scoped to the whole package!
    foreach $city ( @myCities ) {
    ...
    }
    
    print "$city"; # works as expected!