Modulinos: Difference between revisions

Perl, Python, Ruby: stop exporting a function named 'main'.
(Perl, Python, Ruby: stop exporting a function named 'main'.)
Line 492:
 
=={{header|Perl}}==
Perl has scripted main. The code inside <tt>unless(caller) { ... }</tt> only runs when <tt>Life.pm</tt> is the main program.
Perl has scripted main.
 
scriptedmain.pm
 
<lang perl>#!/usr/bin/env perl
 
# Life.pm
package Life;
 
use strict;
use warnings;
 
sub meaning_of_life {
Line 504 ⟶ 506:
}
 
unless(caller) { main; }</lang>
sub main {
print "Main: The meaning of life is " . meaning_of_life() . "\n";
main()}</lang>
}
 
unless(caller) { main; }</lang>
 
test.pl
 
<lang perl>#!/usr/bin/env perl
 
# death.pl
use strict;
use ScriptedMainwarnings;
 
use Life;
print "Test: The meaning of life is " . meaning_of_life() . "\n";</lang>
 
print "Life means " . Life::meaning_of_life . ".\n";
print "Death means invisible scary skeletons.\n";</lang>
 
=={{header|PHP}}==
Line 547 ⟶ 549:
=={{header|Python}}==
Python has scripted main.
 
scriptedmain.py
 
<lang python>#!/usr/bin/env python
 
# life.py
 
def meaning_of_life():
return 42
 
if __name__ == "__main__":
def main():
print "Main: The meaning of life is %s" % meaning_of_life()</lang>
 
<lang python>#!/usr/bin/env python
if __name__=="__main__":
main()</lang>
 
test# death.py
 
<lang python>#!/usr/bin/env python
 
from life import scriptedmainmeaning_of_life
 
print "Test:Life The meaning of life ismeans %s." % scriptedmain.meaning_of_life()</lang>
print "Death means invisible scary skeletons."</lang>
 
=={{header|R}}==
Line 609:
Ruby has scripted main.
 
<lang ruby># life.rb
scriptedmain.rb
 
<lang ruby>#!/usr/bin/env ruby
 
def meaning_of_life
42
end
 
def main
puts "Main: The meaning of life is #{meaning_of_life}"
end
 
if __FILE__ == $0
print puts "TestMain: The meaning of life is " . #{meaning_of_life() . "\n}";</lang>
main
end</lang>
 
<lang ruby># death.rb
test.rb
 
<lang ruby>#!/usr/bin/env ruby
 
require "scriptedmain"'life'
 
puts "Test:Life The meaning of life ismeans #{meaning_of_life}."</lang>
puts "Death means invisible scary skeletons."</lang>
 
=={{header|Tcl}}==
Anonymous user