Help for this page

Select Code to Download


  1. or download this
       defined       #same as defined($_)
       print         #same as print STDOUT $_
       /\sjackson$/  #same as $_ =~ /\sjackson$/
    
  2. or download this
      @only_defined = grep { defined($_) } @somearray;
      %hash_defined = map { $_ => 1 } @only_defined;
    ...
      #and since $_ is the default argument, you can also write
      @only_defined = grep { defined } @somearray;
      @only_begins_with_a = grep { /^a/ } @somearray;
    
  3. or download this
      while (<STDIN>) {
        chomp              # same as chomp $_
        if (/^#/) {....}   # same as if ($_ =~ /^#/) { ....}
      }
    
  4. or download this
    
    #Note this code still won't work - see sherm's explanation below.
    ...
         if($name =~ "jackson")
         print $name . "\n";     #sic - should be { print $name . "\n" }
     }
    
  5. or download this
      while (my $line = <STDIN>) {
        chomp $line;
        if ($line =~ /^#/) {....}
      }