Help for this page

Select Code to Download


  1. or download this
    $_ = 42;
    foreach (1, 2, 3) {
       print "Inside loop: \$_ = [$_]\n";
    }
    print "Outside loop: \$_ = [$_]\n";
    
  2. or download this
    $_ = 42;
    while(<FH>) {
       print "Inside loop: \$_ = [$_]";
    }
    print "Outside loop: \$_ = [$_]\n";
    
  3. or download this
    foreach (@test_array) {
        print qq|Before while: [$_]\n|;
    
    ...
    
        print qq|After while: [$_]\n|;
    }
    
  4. or download this
    foreach my $elem (@test_array) {
        open(IN, $0) || die "No file: $!\n";
        while( defined(my $line = <IN>) ) {  }
        close IN;
    }