Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Given When Syntax

by Laurent_R (Canon)
on Mar 15, 2014 at 16:39 UTC ( [id://1078466] : note . print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    my @array = qw /One Two Three/; 
    my $var = 2;
    print $array[$var], "\n";
    
  2. or download this
    my %hash = ( 1 => One, 2 => Two, 3 => Three);
    my $var = 2;
    print "$hash{$var}\n";
    
  3. or download this
    my ($oper, $rest) = shift, join ' ', @_;
    my $stop = 'stop';
    ...
    else {
        die "Unknown operation: $oper \n";
    }
    
  4. or download this
    my %dispatch_table = (
        stop => sub {run_stop($rest); cleanup();},
    ...
        start => /&run_start(@rest),
        force_start => sub  {run_stop ($rest); cleanup() ; run_start ($res
    +t);},
    );
    
  5. or download this
    my ($oper, $rest) = shift, join ' ', @_;
    if (defined $dispatch_table{$oper}) {
    ...
    } else {
        die "Unknown operation: $oper \n";
    }