PageRenderTime 8ms CodeModel.GetById 1ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/tutorial/language/perl_example_1.e

http://github.com/tybor/Liberty
Specman e | 66 lines | 52 code | 11 blank | 3 comment | 4 complexity | 0723af6cef980dde92fc493de14667ab MD5 | raw file
 1-- compilation command line: se c perl_example_1.e
 2class PERL_EXAMPLE_1
 3
 4create {ANY}
 5   make
 6
 7feature {}
 8   make
 9      local
10         perl: PERL
11      do
12         create perl.make
13         io.flush -- All buffered Eiffel text is written before perl is writing.
14         perl.instruction(once "use strict;print(%"Hello!\n%");")
15         perl.instruction(once "[
16                                print("Perl code in verbatim mode, even % character is allowed!\n");
17                                                                                            ]")
18
19         if perl.existant_variable(once "a") then
20            io.put_string(once "$a does already exist.%N")
21         else
22            io.put_string(once "$a does not exist.%N")
23         end
24
25         io.put_string(once "Declaring $a%N")
26         perl.instruction(once "$a = undef;") -- 'my' should not be used...
27
28         if perl.existant_variable(once "a") then
29            io.put_string(once "$a does exist.%N")
30            if perl.defined_variable(once "a") then
31               io.put_string(once "$a is defined%N")
32            else
33               io.put_string(once "$a is 'undef'%N")
34            end
35         else
36            io.put_string(once "$a does not exist.%N")
37         end
38
39         io.put_string(once "Setting $a to 3*8.%N")
40         perl.instruction(once "$a = 3*8;")
41
42         if perl.defined_variable(once "a") then
43            io.put_string(once "$a is defined%N")
44            io.put_string(once "$a = ")
45            perl.read_variable(once "a")
46            io.put_integer(perl.last_integer)
47            io.put_new_line
48         else
49            io.put_string(once "$a is 'undef'%N")
50         end
51
52         io.put_string(once "Using expression allows to get the %
53                            %result without using variable, so polluting the %
54                            %perl variable name space is avoided.%N%
55                            %2^10=")
56
57         perl.expression(once "2**10+0")
58         -- "+0" converts to int and don't ask me why 2**10 is not treated as integer by perl 
59         -- interpreter
60         
61         io.put_integer(perl.last_integer)
62         io.put_new_line
63         perl.destroy
64      end
65
66end -- class PERL_EXAMPLE_1