Help for this page

Select Code to Download


  1. or download this
    open(FILE "<file.dat") || die "cannot open file";
    
  2. or download this
    sub insertQuarter {
        my ($coin) = @_;
    ...
        initializeGame();
        startGame();
    }
    
  3. or download this
    # just return a false value and allow the
    # calling code to deal with the false return
    ...
    # call stack information, set error variable,
    # and return a specific value.
    (defined($coin) && $coin == 25) || return errorHandler("You must inser
    +t 25 cents");
    
  4. or download this
    #!/usr/bin/perl
    
    ...
        'Assert'          => sub { eval { Assert($_)          } for (@nums
    +) },    
        'Assert2'         => sub { eval { Assert2($_)         } for (@nums
    +) },   
    });
    
  5. or download this
    Benchmark: timing 10000 iterations of Assert, Assert2, IfBlocks, IfSta
    +tement, UnlessBlocks, UnlessStatement...
             Assert:  4 wallclock secs ( 2.38 usr +  0.02 sys =  2.40 CPU)
    + @ 4166.67/s (n=10000)
    ...
    IfStatement     1299/s             52%          49%       3%          
    +--   -69%    -69%
    Assert          4167/s            388%         378%     231%        22
    +1%     --     -0%
    Assert2         4184/s            390%         380%     233%        22
    +2%     0%      --
    
  6. or download this
    sub onlyAcceptFooObjects {
        my ($foo) = @_;
    ...
            || die "This method only accepts Foo objects";
        # ...
    }