Switch on sub : switch « Statement « Perl






Switch on sub

 


#!/usr/bin/perl -w
use strict;
use Switch;

my $input;

sub lessthan { $input < $_[0] };

$input=int(<>);
switch ( \&lessthan ) {
    case 10           { print "less than 10\n" }
    case (100-$input) { print "less than 50\n" }
    case 100          { print "less than 100\n" }
}

   
  








Related examples in the same category

1.The Switch.pm Module
2.Swich for data type