Help for this page

Select Code to Download


  1. or download this
    for my $i ( 0..11 ) {
       print "yes it's a month\n" if $month eq $monthnames[$i];
    ...
    }
    
    print "Yes it's a month\n" if grep { $_ eq $month } @monthnames;
    
  2. or download this
    my @months = qw( jan feb mar apr may jun jul aug sep oct nov dec);
    my %monthnames;
    # create lookup table
    $monthnames{$_}++ for @months;
    print "Yes it's a month!" if exists $monthnames{$month};
    
  3. or download this
    $a = 1;      # set $a to 1
    $a == 1;     # returns a true value if $a is numerically equal to 1
    $a eq 'foo'  # returns a true value if $a is equal to the string value
    + 'foo'
    
  4. or download this
    print "What, a string is numerically == 0?" if 'foo' == 0;