File: test16.p

package info (click to toggle)
libdevel-nytprof-perl 6.14%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,888 kB
  • sloc: perl: 5,497; javascript: 4,033; ansic: 107; makefile: 27
file content (34 lines) | stat: -rw-r--r-- 552 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# tests given/when.  Can only be tested by Perl 5.10 or later.

use warnings;
use strict;

use feature ":5.10";
no if "$]" >= 5.018, warnings => "experimental";

sub foo {
    my $whameth = shift;
    given ($whameth) {
        when(/\d/) {
            say "number-like";
        }
        when(/\w/) {
            say "word-like";
        }
    }
}

sub bar {
    my $zlott = shift;
    if($zlott =~ /\d/) {
        print "number-like\n";
    } elsif($zlott =~ /\w/) {
        print "word-like\n";
    } 
}


foo("baz");
foo(17);
bar("baz");
bar(17);