Debian Codegraph @

examples/prism-perl.html

raw symbols SCIP
1 <h2>Comments</h2>
2 <pre><code># Single line comment
3 =head1 Here There
4 Be Pods!
5 =cut</code></pre>
6
7 <h2>Strings</h2>
8 <pre><code>q/foo bar baz/;
9 q awhy not ?a;
10 qw(foo bar baz) q{foo bar baz}
11 q[foo bar baz] qq&lt;foo bar baz>
12 "foo bar baz" 'foo bar baz' `foo bar baz`</code></pre>
13
14 <h2>Regex</h2>
15 <pre><code>m/foo/ s/foo/bar/
16 m zfooz s zfoozbarz
17 qr(foo) m{foo} s(foo)(bar) s{foo}{bar}
18 m[foo] m&lt;foo> tr[foo][bar] s&lt;foo>&lt;bar>
19 /foo/i
20 </code></pre>
21
22 <h2>Variables</h2>
23 <pre><code>${^POSTMATCH}
24 $^V
25 $element_count = scalar(@whatever);
26 keys(%users) = 1000;
27 $1, $_, %!;</code></pre>
28
29 <h2>Numbers</h2>
30 <pre><code>12345
31 12345.67
32 .23E-10 # a very small number
33 3.14_15_92 # a very important number
34 4_294_967_296 # underscore for legibility
35 0xff # hex
36 0xdead_beef # more hex
37 0377 # octal (only numbers, begins with 0)
38 0b011011 # binary</code></pre>
39
40 <h2>Full example</h2>
41 <pre><code>sub read_config_file {
42 my ($class, $filename) = @_;
43
44 unless (defined $filename) {
45 my $home = File::HomeDir->my_home || '.';
46 $filename = File::Spec->catfile($home, '.pause');
47
48 return {} unless -e $filename and -r _;
49 }
50
51 my %conf;
52 if ( eval { require Config::Identity } ) {
53 %conf = Config::Identity->load($filename);
54 $conf{user} = delete $conf{username} unless $conf{user};
55 }
56 else { # Process .pause manually
57 open my $pauserc, '&lt;', $filename
58 or die "can't open $filename for reading: $!";
59
60 while (&lt;$pauserc>) {
61 chomp;
62 next unless $_ and $_ !~ /^\s*#/;
63
64 my ($k, $v) = /^\s*(\w+)\s+(.+)$/;
65 Carp::croak "multiple enties for $k" if $conf{$k};
66 $conf{$k} = $v;
67 }
68 }
69
70 return \%conf;
71 }</code></pre>