~ubuntu-branches/ubuntu/wily/xslthl/wily

« back to all changes in this revision

Viewing changes to examples/sources/example-perl.xml

  • Committer: Package Import Robot
  • Author(s): Mathieu Malaterre
  • Date: 2013-05-16 08:59:07 UTC
  • mfrom: (4.1.2 sid)
  • Revision ID: package-import@ubuntu.com-20130516085907-ujk9f81x8w344ch1
Tags: 2.1.0-2
Upload to sid

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?xml version="1.0" encoding="UTF-8"?>
2
 
<example-document>
3
 
        <header>Perl code</header>
4
 
        <para>Example Perl code</para>
5
 
        <code xml:whitespace="preserve" language="perl">
6
 
                <![CDATA[
7
 
#!/usr/bin/perl
8
 
use strict;
9
 
use warnings;
10
 
 
11
 
#######################################
12
 
#
13
 
#   99 bottles of beer on the wall
14
 
#   Written in object oriented Perl
15
 
#
16
 
#######################################
17
 
my $beer = Bottles->new();
18
 
$beer->Take_One_Down() while $beer->Remaining();
19
 
 
20
 
package Bottles;
21
 
 
22
 
sub new
23
 
{
24
 
        my $bottles = 99;
25
 
        bless \$bottles;
26
 
}
27
 
 
28
 
sub Take_One_Down
29
 
{
30
 
        my $self = shift;       
31
 
        my $s = $$self == 1 ? '' : 's';
32
 
        
33
 
        print "$$self bottle$s of beer on the wall,\n";
34
 
        print "$$self bottle$s of beer.\n";
35
 
        print "Take one down, pass it around.\n";
36
 
        
37
 
        $$self--;
38
 
        
39
 
        $s = $$self == 1 ? '' : 's';
40
 
        
41
 
        print "$$self bottle$s of beer on the wall.\n\n";
42
 
}
43
 
 
44
 
sub Remaining
45
 
{
46
 
        my $self = shift;
47
 
        return $$self;  
48
 
}
49
 
                ]]>
50
 
        </code>
51
 
        <para>Origin: http://www.99-bottles-of-beer.net/language-perl-648.html</para>
52
 
        <para>Alternative</para>
53
 
        <code xml:whitespace="preserve" language="perl">
54
 
                <![CDATA[
55
 
#!/usr/bin/perl
56
 
# Jim Menard     jimm@{bbn,io}.com     (617) 873-4326    http://www.io.com/~jimm/
57
 
$nBottles = $ARGV[0];
58
 
$nBottles = 100 if $nBottles eq '' || $nBottles < 0;
59
 
 
60
 
foreach (reverse(1 .. $nBottles)) {
61
 
    $s = ($_ == 1) ? "" : "s";
62
 
    $oneLessS = ($_ == 2) ? "" : "s";
63
 
    print "\n$_ bottle$s of beer on the wall,\n";
64
 
    print "$_ bottle$s of beer,\n";
65
 
    print "Take one down, pass it around,\n";
66
 
    print $_ - 1, " bottle$oneLessS of beer on the wall\n";
67
 
}
68
 
print "\n*burp*\n";
69
 
                ]]>
70
 
        </code>
71
 
        <para>Origin: http://www.99-bottles-of-beer.net/language-perl-539.html</para>
72
 
        <para>Some additional examples</para>
73
 
        <code xml:whitespace="preserve" language="perl">
74
 
                <![CDATA[
75
 
print <<"END";
76
 
 
77
 
Dear $recipient, 
78
 
 
79
 
I wish you to leave Sunnydale and never return.
80
 
 
81
 
Not Quite Love,
82
 
$sender
83
 
 
84
 
END
85
 
 
86
 
print <<'END';
87
 
Dear $recipient,
88
 
 
89
 
I wish you to leave Sunnydale and never return.
90
 
 
91
 
Not Quite Love,
92
 
$sender
93
 
END
94
 
 
95
 
 
96
 
print <<END;
97
 
Dear $recipient,
98
 
 
99
 
I wish you to leave Sunnydale and never return.
100
 
 
101
 
Not Quite Love,
102
 
$sender
103
 
END             
104
 
 
105
 
fin
106
 
                ]]>
107
 
        </code>
108
 
</example-document>
 
 
b'\\ No newline at end of file'