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