Help for this page

Select Code to Download


  1. or download this
    for(my $x = 0; $x <= $#array; $x++) {
        next unless $array[$x];
        # do stuff with $x and $array[$x]
    }
    
  2. or download this
    my %hash = 
        map { $x => $y } 
        grep { my $y = $list[$x]; $y ne $undef; [$x, $y] }
        for(my $x = 0; $x <= $#list; $x++);
    
  3. or download this
    $list{100} = 'dog';
    $list{435} = 'cat';
    $list{1040} = 'tax form';
    ...
    while(($index, $element) = each %list) {
        # do stuff with $index and $element
    }