Help for this page

Select Code to Download


  1. or download this
    sub getArrayIndex {
         my $value = shift;
    ...
         }
         return -1;
    }
    
  2. or download this
    for ($i=0,$i<$x,$i++)
    
  3. or download this
    # to just iterate over an array; each element assigned to $_
    # changing $_ changes the original array element
    ...
    for $i(0..10) {
        # $i will be set to 0 to 10 in sequence
    }
    
  4. or download this
    for (0..$#array) { }
    for (0..@array) { }
    
  5. or download this
    @array = qw(1);
    print "My array @array\n";
    ...
        for (0..@array) {$array[$_]++}
    }
    print "My array @array\n";
    
  6. or download this
    My array 1
    My array 12 11 10 9 8 7 6 5 4 3 2 1
    
  7. or download this
    # really short idiomatic version
    
    ...
    @array = qw(0 2 4 6 8 10 12);
    print getArrayIndex(6,@array),"\n";
    print getArrayIndex(5,@array),"\n";